$(document).ready(function() {
	 $.urlParam = function(name, url){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
    if (!results) { return 0; }
    return results[1] || 0;
  }; 
	
	$(".colorbox, .screenshot").colorbox();
//	$(".screenshot2").colorbox({ arrowKey:true, loop:false});	
	$(".screenshot2").colorbox({ arrowKey:false, loop:false, previous:'Windows version', next:'Linux version', current:''});	
	$(".screen").colorbox({iframe:true, innerHeight:function(){return $.urlParam('height', $(this).attr('href'))}, innerWidth:function(){return $.urlParam('width', $(this).attr('href'))}});	
	$(".download_overlay").colorbox({innerWidth:'690px', innerHeight:'470px', iframe:true, scrolling:false });
	$(".linux_download_overlay").colorbox({innerWidth:'620px', innerHeight:'420px', iframe:true, scrolling:false });		
	$(".oem_request").colorbox({innerWidth:'855px', innerHeight:'540px', iframe:true, scrolling:false});	
	$(".supported_devices").colorbox({innerWidth:'725px', innerHeight:'530px', iframe:true, scrolling:false});
	$("#win_ownload_link").colorbox();
	var licLinks = $(".wikilinks");
		$.each(licLinks, function(){
			this.href = this.href + '?ajax=true';
			$(this).colorbox({
				iframe:true, innerWidth:'80%', innerHeight:'70%'});
		});

	
	var i=0;
	var sync_img = $('#sync_dev_img a');
	var sync_text = $('#nav_link .center span');	
	var cur = sync_img.get(0);
	var cur_text = sync_text.get(0);
	var count = sync_img.size()-1;

	function go_to(inc)
	{
		if (i > count)
			{
//			 	i=count;
			 	i=0;
//				$('#nav_next').addClass('notactive');
			}
		else if (i < 0)
			{
//				i=0;
				i=count;
	//			$('#nav_prev').addClass('notactive');
			}

		else
			{	
				$('#nav_prev').removeClass('notactive');
				$('#nav_next').removeClass('notactive');
			}
		if ($(cur)!=undefined)
		{
			$(cur).fadeOut('fast', function(){cur =  sync_img.get(i);$(cur).fadeIn('fast');});
			$(cur_text).fadeOut('fast', function(){cur_text =  sync_text.get(i);$(cur_text).fadeIn('fast');});
		}

	}
/*--------------------*/
	function go_step(elem, inc)
	{
		if ($(elem).hasClass('notactive'))
			return false;
		prev_i = i;
		i = i + inc;
		go_to(inc);
		return false;	
	}
	
	$('#nav_next').bind('click', function(){go_step(this,1)});
	$('#nav_prev').bind('click', function(){go_step(this,-1)});
/*	var info_link=$(".info_link");
	$.each(info_link,function(){this.href=this.href+'?ajax=true';
								$(this).colorbox({iframe:true,innerWidth:'80%',innerHeight:'70%',speed:200,opacity:0.8})});
								*/
	$('#download_btn').colorbox({width:"50%",height:"300px",inline:true,href:"#download_overlay"});								
});
