$(document).ready( function() {
    
    // open picture navigation
   
	$("div.addnavhover").attr({id: "navhover"});
	$("ul.open-project-nav").hide();
	
	$('#navhover #open-project-pix-right,#navhover .open-project-nav').hover(function(){
		$("div#open-project-pix-right a").addClass("mouse-over");
		$("ul.open-project-nav").show();
	},function(){
		$("div#open-project-pix-right a").removeClass("mouse-over");
		$("ul.open-project-nav").hide();
	});
	
	
	// startpage flash
    
/*    $('#fla').html('<object type="application/x-shockwave-flash" data="misc/mediaparks-flash.swf" width="100%" height="610">'+
			'<param name="flashVars" value="xmlPath=contents.xml" />'+
			'<param name="movie" value="misc/mediaparks-flash.swf" />'+
			'<param name="quality" value="high" />'+
			'<param name="bgcolor" value="#AAAAAA" />'+
			'<img src="spacer.gif" width="990" height="610" alt="No FLASH Player installed" /></object>');
		*/
		// playing within code
    
		var heig = $('#open-project-pix-right img').height();
		var wid = $('#open-project-pix-right img').width();
		//alert(heig + 'x' + wid);
    
		// price hint hover - show hide
		
		$(".price-hint .link").hide();
		
		$('.price-hint').hover(function(){
			$(".price-hint .link").slideDown(300);
		},function(){
			$(".price-hint .link").hide();
		});
		
		// price-hint flash
		siteLang = (typeof(siteLang) != 'undefined') ? siteLang : 1;
		$('#price-hint').html('<object type="application/x-shockwave-flash" data="images/flash/get-price-quote.swf" width="148" height="56">'+
				'<param name="flashVars" value="xmlPath=files/flash/config' + siteLang + '.xml" />'+
				'<param name="movie" value="images/flash/get-price-quote.swf" />'+
				'<param name="quality" value="high" />'+
				'<param value="transparent" name="wmode" />'+
				'<img src="images/design/noflash.gif" width="150" height="39" alt="No FLASH Player installed" /></object>');
		
		// info popup on services page
		
		
	$(function () {
		var tabContainers = $('div.table-data > div.info-popup');
				
		$('div.table-data ul.link-list a').hover(function () {
				
			$(this).closest('ul.link-list').prevAll('div.info-block').hide();
			$(this).closest('div.table-data').addClass('bg');
			
			//tabContainers.hide().filter(this.hash).fadeIn('200');
			tabContainers.hide().filter(this.hash).show();
			
			$('div#pay-info ul.link-list li').removeClass('active');
			$(this).parent().addClass('active');
			return false;
				
		},function(){
			 $(this).closest('ul.link-list').prevAll('div.info-block').show();
			 $(this).closest('div.table-data').removeClass('bg');
			 $("div.info-popup").hide();
			 $(this).parent().removeClass('active');
		});
	});
		
	// text doc table styled header
	
	$('.price-form').submit(function(){
		$('#hw').val('world');
	});
    
	$("div#text-doc table tr:first").addClass("header");
	
	$('a[rel=external]').attr('target', '_blank');

	$("#works").easySlider();


	window.socialPlugins = function(obj) {
		if (obj.social == 'twitter') {
			window.open('http://twitter.com/share?url='+encodeURIComponent(window.location.href)+'&text='+encodeURIComponent($('#title')[0].innerHTML),
			'','location=1,status=1,scrollbars=0,resizable=0,width=530,height=400');
			return false;
		}
		if (obj.social == 'facebook') {
			window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(window.location.href)+'&t='+encodeURIComponent($('#title')[0].innerHTML),
			'','location=1,status=1,scrollbars=0,resizable=0,width=530,height=400');
			return false;
		}
		if (obj.social == 'draugiem') {
			DraugiemSay($('#title')[0].innerHTML,window.location.href,'mediaparks.lv');
			return false;
		}
		return false;
	}

	window.socialPluginForList = function(obj) {

		if (obj.social == 'twitter') {
			window.open('http://twitter.com/share?url='+encodeURIComponent('http://'+location.host+$('#news'+obj.id+' div h4 a').attr('href'))+'&text='+encodeURIComponent($('#news'+obj.id+' div h4 a').html()),
			'','location=1,status=1,scrollbars=0,resizable=0,width=530,height=400');
			return false;
		}
		if (obj.social == 'facebook') {
			window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent('http://'+location.host+$('#news'+obj.id+' div h4 a').attr('href'))+'&t='+encodeURIComponent($('#news'+obj.id+' div h4 a').html()),
			'','location=1,status=1,scrollbars=0,resizable=0,width=530,height=400');
			return false;
		}
		if (obj.social == 'draugiem') {
			DraugiemSay($('#news'+obj.id+' div h4 a').html(),'http://'+location.host+$('#news'+obj.id+' div h4 a').attr('href'),'mediaparks.lv');
			return false;
		}
		return false;
	}
	function DraugiemSay(title, url, titlePrefix) {
		window.open(
			'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent(title) +
					'&link=' + encodeURIComponent(url) +
					(titlePrefix ? '&titlePrefix=' + encodeURIComponent(titlePrefix) : ''), 'dd',
			'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
		);

		return false;
	}

	$('.socialPic .facebook').click(function(){socialPlugins({social: 'facebook'});return false;});
	$('.socialPic .draugiem').click(function(){socialPlugins({social: 'draugiem'});return false;});
	$('.socialPic .twitter').click(function(){socialPlugins({social: 'twitter'});return false;});
	
	$('.socialLinks .facebook').click(function(){
		
		var id = $(this).closest('object').attr('id').split('-').pop();
		console.log('hi F!'+id);
		socialPluginForList({social: 'facebook', id: id});
		return false;
	});
	$('.socialLinks .draugiem').click(function(){
		var id = $(this).closest('object').attr('id').split('-').pop();
		socialPluginForList({social: 'draugiem', id: id});
		return false;
	});
	$('.socialLinks .twitter').click(function(){
		var id = $(this).closest('object').attr('id').split('-').pop();
		socialPluginForList({social: 'twitter', id: id});
		return false;
	});



});
