$(document).ready(function() {


	// download SM facebook overlay
	var location = String(window.location);
	if (
			location.indexOf('sync_mac_google.html') != -1 || 
			location.indexOf('sync_mac_nokia.html') != -1 || 
			location.indexOf('sync_mac_windows_mobile.html') != -1 || 
			location.indexOf('sync_mac_pc.html') != -1 || 
			location.indexOf('sync_several_macs.html') != -1 || 
			location.indexOf('sync_mac_google.html') != -1 || 
			location.indexOf('sync_mac_psp.html') != -1 || 
			location.indexOf('sync_mac_usb_drive.html') != -1 || 
			location.indexOf('backup_mac_online.html') != -1 || 
			location.indexOf('sync_mac_android.html') != -1 || 
			location.indexOf('htc_sync.html') != -1 || 
			location.indexOf('samsung_sync.html') != -1 || 
			location.indexOf('mac_synchronization.html') != -1 || location.indexOf('sync_mac_dropbox.html') != -1 || location.indexOf('sync_mac_ipod.html') != -1 || location.indexOf('iphone_sync.html') != -1 || location.indexOf('sync_mac_ipad.html') != -1 || location.indexOf('sync_mac_ios.html') != -1 || location.indexOf('sync_mac_ipod_touch.html') != -1 || location.indexOf('sync-mac.html')) {
/*	    $('a[href="http://sync-mac.com/download/syncmate.dmg"], a[href="http://mac.eltima.com/download/syncmate.dmg"], a[href="/download/syncmate.dmg"]').bind('click', function() {
	        activateOverlay();
	    });
	    $('a[href="http://mac.eltima.com/download/syncmate.dmg"]').bind('click', function() {
	        activateOverlay();
	    });
	    $('a[href="/download/syncmate.dmg"]').bind('click', function() {
	        activateOverlay();
	    });
*/	}
	function activateOverlay() {
	    //if (!getCookie('fcbOverlay')) // show one time
	    if ( true ) // always show
	    {
	    	var lang = $('html').attr('lang');
	    	
	    	if( lang != "en" )
	    	{
	    		lang = lang+'/';
	    	}
	    	else
	    	{
	    		lang = '';
	    	}	
	        setTimeout(function() {
	            $.fn.colorbox({
	                iframe: true,
	                innerWidth: '680px',
	                innerHeight: '394px',
	                speed: 200,
	                opacity: 0.8,
	                href: "http://mac.eltima.com/"+lang+"facebook-overlay",
	                });
	            setCookie('fcbOverlay', '1', 1);
	        }, 2000);
	        return true;
	    } else {
	        return this;
	    }
	}
	function setCookie(name, value, days) {
	    var location = String(window.location);
	    name = name + location.replace('http://mac.eltima.com/', '');
	    if (days) {
	        var date = new Date();
	        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
	        var expires = "; expires=" + date.toGMTString();
	    } else
	        var expires = "";
	    document.cookie = name + "=" + value + expires + "; path=/";
	}
	function getCookie(name) {
	    var location = String(window.location);
	    name = name + location.replace('http://mac.eltima.com/', '');
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for (var i = 0; i < ca.length; i++) {
	        var c = ca[i];
	        while (c.charAt(0) == ' ')
	            c = c.substring(1, c.length);
	        if (c.indexOf(nameEQ) == 0)
	            return c.substring(nameEQ.length, c.length);
	    }
	    return null;
	}
	
	
	
	
	
	
	
$.urlParam = function(name, url){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
    if (!results) { return 0; }
    return results[1] || 0;
  }; 
  
		$('a').filter(function () { return (/\.(exe|dmg|apk|zip|rar|bz2)(?:\?([^#]*))?(?:#(\.*))?$/i.test($(this).attr('href'))) && ($(this).attr('notrack') == undefined); }).bind('click', function(){
			_gaq.push(['_trackPageview',$(this).attr('href')]);
				var href = String($(this).attr('href'));
				var index = href.indexOf('syncmate.dmg')
				if (index >= 0){
					activateOverlay();
				}
			});
	
	if(String(window.location).indexOf('&page=')!=-1)
		{
			var location = String(window.location);
			$.colorbox({iframe:$.urlParam('iframe', location), innerHeight:$.urlParam('height', location), innerWidth:$.urlParam('width', location), href:$.urlParam('page', location), scrolling:false});
		}

    var tab_1 = $('#tab_1');
    var tab_2 = $('#tab_2');
    var tab_3 = $('#tab_3');
    var tab_4 = $('#tab_4');

    var main_features = $('#main_features');
    var product_information = $('#product_information');
    var corporate_license = $('#corporate_solution');
    var forth_tab = $('#fourth_tab');

    tab_1.bind('click', function() {
        tab_1.attr('class', 'selTab');
        tab_2.attr('class', 'tab');
        tab_3.attr('class', 'tab');

        main_features.css('display', 'block');
        product_information.css('display', 'none');
        corporate_license.css('display', 'none');
        if(tab_4) {            
            tab_4.removeClass('selTab').addClass('tab');	
            forth_tab.css('display', 'none');
        }
		hidebuttondown($(this));		
    });

    tab_2.bind('click', function() {
        tab_1.attr('class', 'tab');
        tab_2.attr('class', 'selTab');
        tab_3.attr('class', 'tab');

        main_features.css('display', 'none');
        product_information.css('display', 'block');
        corporate_license.css('display', 'none');
        if(tab_4) {            
            tab_4.removeClass('selTab').addClass('tab');	
            forth_tab.css('display', 'none');
        }
		hidebuttondown($(this));		
    });

    tab_3.bind('click', function() {
        tab_1.attr('class', 'tab');
        tab_2.attr('class', 'tab');
        tab_3.attr('class', 'selTab');

        main_features.css('display', 'none');
        product_information.css('display', 'none');
        corporate_license.css('display', 'block');
        if(tab_4) {            
            tab_4.removeClass('selTab').addClass('tab');			
            forth_tab.css('display', 'none');
        }
		hidebuttondown($(this));		
    });
    
    if(tab_4) {
        tab_4.bind('click', function() {
            tab_1.attr('class', 'tab');
            tab_2.attr('class', 'tab');
            tab_3.attr('class', 'tab');
            tab_4.removeClass('tab').addClass('selTab');
		
            main_features.css('display', 'none');
            product_information.css('display', 'none');
            corporate_license.css('display', 'none');
            forth_tab.css('display', 'block');
		hidebuttondown($(this));			
        });
        
    }

    if(String(window.location).indexOf('#open-the-third-tab') != -1) {
        tab_1.attr('class', 'tab');
        tab_2.attr('class', 'tab');
        tab_3.attr('class', 'selTab');

        main_features.css('display', 'none');
        product_information.css('display', 'none');
        corporate_license.css('display', 'block');
    }
    
    $('.customTabSwith').bind('click', function(){
        tab_1.attr('class', 'tab');
        tab_2.attr('class', 'tab');
        tab_3.attr('class', 'tab');
        tab_4.removeClass('tab').addClass('selTab');
	
        main_features.css('display', 'none');
        product_information.css('display', 'none');
        corporate_license.css('display', 'none');
        forth_tab.css('display', 'block');
        hidebuttondown($(this));			
    });
    
    
    
    
    
    
    $('.e-button').bind('click', function() {
        var link = $(this);
        link.removeClass('e-button-p');
        link.addClass('e-button');
    });

    $('.e-button').bind('mousedown', function() {
        var link = $(this);
        link.removeClass('e-button');
        link.addClass('e-button-p');
    });

    $('.e-button').bind('mouseup', function() {
        var link = $(this);
        link.removeClass('e-button-p');
        link.addClass('e-button');
    });

    $('.e-button').bind('mouseout', function() {
        var link = $(this);
        link.removeClass('e-button-p');
        link.addClass('e-button');
    });

    $('.eb-button').bind('click', function() {
        var link = $(this);
        link.removeClass('eb-button-p');
        link.addClass('eb-button');
    });

    $('.eb-button').bind('mousedown', function() {
        var link = $(this);
        link.removeClass('eb-button');
        link.addClass('eb-button-p');
    });

    $('.eb-button').bind('mouseup', function() {
        var link = $(this);
        link.removeClass('eb-button-p');
        link.addClass('eb-button');
    });

    $('.eb-button').bind('mouseout', function() {
        var link = $(this);
        link.removeClass('eb-button-p');
        link.addClass('eb-button');
    });

	$(".colorbox").colorbox();
	$(".youtube").colorbox({iframe:true, innerWidth:'505px', innerHeight:'410px'});
	$(".er_contact").colorbox({iframe:true, innerWidth:'540px', innerHeight:'670px', speed:200,opacity:0.8});
	$(".screenshot").colorbox({opacity:0.8});
	$(".try_link").colorbox({width:"50%", height:"250px", inline:true, href:"#download_overlay"});
	$(".wiki_site").colorbox({width:"50%", height:"40%",inline:true, href:"#wiki_site"});
	$("#smart_phones_link").colorbox({inline:true, href:"#smarts_table"});
	$(".supCommunicator").colorbox({inline:true, href:"#pockets_table"});
	$("#nokia_table_link").colorbox({width:"655px",height:"60%",inline:true, href:"#nokia_table"});
	$(".try_link_fla").colorbox({width:"50%", height:"250px",inline:true, href:"#download_overlay_fia"});
	$("#premium_overlay_link").colorbox({width:"50%", height:"310px",inline:true, href:"#premium_overlay"});	
	$(".youtube").colorbox({iframe:true, innerWidth:'505px', innerHeight:'410px'});	
	$("#try_link_folx, #try_link_folx2").colorbox({iframe:true, innerWidth:'705px', innerHeight:'570px', scrolling:false, href: function(){ var url = $(this).attr('value'); return url;}});	
	$("#try_link_elmedia, #try_link_elmedia2").colorbox({iframe:true, innerWidth:'705px', innerHeight:'630px', scrolling:false, href: function(){ var url = $(this).attr('value'); return url;}});	
//	$("#try_link_sm, #try_link_sm2").colorbox({iframe:true, innerWidth:'855px', innerHeight:'710px', scrolling:false, href: function(){ var url = $(this).attr('value'); return url;}});	

/*	$("#try_link_sm, #try_link_sm2").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('value'));},
										innerHeight:function(){return $.urlParam('height', $(this).attr('value'));},
										iframe:true, scrolling:false, href: function(){return $.urlParam('href', $(this).attr('value'));}});	
*/

//	$("#try_link_sm, #try_link_sm2").colorbox({innerWidth:'865px', innerHeight:'690px', scrolling:false, inline:true, href:"#download_overlay"});			
//	$(".try_link_sm").colorbox({innerWidth:'865px', innerHeight:'710px', scrolling:false, href: function(){ var url = $(this).attr('rel'); return url;}});			
//	$(".try_link_sm").colorbox({innerWidth:'865px', innerHeight:'690px', scrolling:false, inline:true, href:"#download_overlay"});	

//	$("#elmedia_upgrade_link").colorbox({innerWidth:'865px', innerHeight:'490px', title:false, scrolling:false, iframe:true,href: function(){ var url = $(this).attr('rel'); return url;}});							
	$("#elmedia_upgrade_link").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('rel'));},
										innerHeight:function(){return $.urlParam('height', $(this).attr('rel'));},
										title:false, scrolling:false, iframe:true,href: function(){ var url = $(this).attr('rel'); return url;}});							
	$(".contact_request").colorbox({innerWidth:'870px', innerHeight:'495px',  scrolling:false, iframe:true});
	$(".contact_request_sm").colorbox({innerWidth:'870px', innerHeight:'530px',  scrolling:false, iframe:true});
	$(".contact_request_sm_fr").colorbox({innerWidth:'870px', innerHeight:'550px',  scrolling:false, iframe:true});
	
//	$(".request_release_sm").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('href'));},
//										innerHeight:function(){return $.urlParam('height', $(this).attr('href'));},
//										title:false, scrolling:false, iframe:true, href: function(){return $.urlParam('href', $(this).attr('href'));}});	

	$(".request_release_sm").colorbox({innerWidth:870,
					   innerHeight:520,
    					title:false, scrolling:false, iframe:true, href: function(){return $.urlParam('href', $(this).attr('href'));}});	
	$(".contact_request2, .screenshot2, .overlay_request, .request_upgrade").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('href'));},
										innerHeight:function(){return $.urlParam('height', $(this).attr('href'));},
										title:false, scrolling:false, iframe:true,href: function(){ return $(this).attr('href');}});							
	
	
	$(".request_release_folx").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('href'));},
											innerHeight:function(){return $.urlParam('height', $(this).attr('href'));},
										title:false, scrolling:false, iframe:true});							
	/*if(!$.browser.msie){
			$("#download_overlay, .download_overlay").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('value'));},
										innerHeight:function(){return $.urlParam('height', $(this).attr('value'));},
										title:true, notshowbtns: true, scrolling:false, iframe:true, href: function(){return $.urlParam('href', $(this).attr('value'));}});
									 	}	*/
/*	if(!$.browser.msie){
			$("#downloader, .downloader").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('value'));},
										innerHeight:function(){return $.urlParam('height', $(this).attr('value'));},
										title:true, scrolling:false, iframe:true, href: function(){return $.urlParam('href', $(this).attr('value'));}});
									 	}	
									 	*/
	$(document).bind('cbox_complete', function(){
        			   if (window.Cufon !== undefined)
						   	{
							 Cufon.replace(".ArialRoundedMTBold", { fontFamily: 'Arial Rounded MT Bold'});
							}

				$('#elmedia_do .download_button a, #folx_do .download_button a').bind('click', function(){$('#cboxClose').click()});
		});		

// upgrade Now button
		$("#upgradeNow option:first-child").attr('selected', 'selected');
		$("#upgradeNow").change( function()
		{
			productVer 	= $(this).attr('rel');
			selectedVal = $(this).val();
			productId 	= $(this).attr('class').replace('pid_', '');
			
			if(productId == 133)
			{
				if (parseInt(productVer) == parseInt(selectedVal))
				{
					$("#upgrade_link").colorbox({width:"50%", inline:true, href:"#upgrade_info_container p"});	
				}
				else
				{
					
					$("#upgrade_link").removeClass('cboxElement').removeData('colorbox'); 
				
					$("#upgrade_link").colorbox({innerWidth:function(){return $.urlParam('width', $(this).attr('href'));},
						innerHeight:function(){return $.urlParam('height', $(this).attr('href'));},
						title:false, scrolling:false, iframe:true,href: function(){ return $(this).attr('href');}});		
				}
			}
			else
			{
				if (parseInt(productVer) == parseInt(selectedVal))
				{
					$("#upgrade_link").colorbox({width:"50%", inline:true, href:"#upgrade_info_container p"});	
				}
				else
				{
					$("#upgrade_link").removeClass('cboxElement').removeData('colorbox');
				}
			}	
		});

});
function hidebuttondown(obj)
{
	if (obj.attr('id')==$('#button_down').attr('lang'))
			$('#button_down').css('display', 'none');
		else
			$('#button_down').css('display', 'block');	
}





