jQuery.noConflict();

FoOsmoz = window.FoOsmoz || new Object();

jQuery(document).ready(function() {	
    if ( (/MSIE 6\.0/).test(navigator.userAgent) && !(/MSIE 7\.0/).test(navigator.userAgent) && !(/MSIE 8\.0/).test(navigator.userAgent) ) {
        DD_belatedPNG.fix(".FixPng");
    }                       
    jQuery(".NavBar").addNavigation({
        event: "click"
    });
	
	// used for display method.
	jQuery(".AOH_Tab > ul > li > a").bind("click",function() {
		if (!jQuery(this).hasClass("Clicked")) {
			jQuery(".AOH_Tab > ul > li > a").removeClass("Clicked");
			jQuery(this).addClass("Clicked");
			jQuery(".AOH_Scroll").removeClass("Active");							
			jQuery("#"+ jQuery(this).attr("rel")).addClass("Active");
		}
		return false;
	});
	
	jQuery(".AOI_Tab > ul > li > a").bind("click",function() {
		if (!jQuery(this).hasClass("Clicked")) {
			jQuery(".AOI_Tab > ul > li > a").removeClass("Clicked");
			jQuery(this).addClass("Clicked");
			jQuery(".AOI_Cnt").removeClass("Active");							
			jQuery("#"+ jQuery(this).attr("rel")).addClass("Active");
		}
		return false;
	});
	
	
	jQuery(".AOH_Background > a").bind("click",function() {
			jQuery(".AOH_Tab > ul > li > a").removeClass("Clicked");
			jQuery(".AOH_Scroll").removeClass("Active");		
			jQuery(".AOI_Cnt").removeClass("Active");		
			jQuery("#"+ jQuery(this).attr("rel")).addClass("Active");
		return false;
	});
	// end.
	
	// use for main navigation
	// main navigation width
	var navWidth = jQuery('div.ADP_Block03').outerWidth();	

	// preview or live mode 
	if (jQuery('div.ADP_Header_Block').html() == "") {
		// extend main navigation width
		navWidth += jQuery('div.ADP_Header_Block').outerWidth();
		
		// set new width for the right zone = 0
		jQuery('div.ADP_Header_Block').hide();
		// set new width for the main navigation
		jQuery('div.ADP_Block03').css({'width': navWidth +'px'});
	}
	//Fix issue #3041
	var length = jQuery('.MainNav > li').length;
	var ulWidth = 0;
	var liWidth = new Array();
	jQuery('.MainNav > li').each(function(i) {
		if(i == 0) {
			ulWidth += jQuery(this).outerWidth() + 0.9;
		} else {
			ulWidth += jQuery(this).outerWidth() + 0.9;
		}
		liWidth.push(jQuery(this).outerWidth());
	});
	
	// fix issue #2876: the first section aligned with the content on zone "TopZone1"
	var exWidth = (navWidth - 0.45*length*2 - ulWidth)/(length*2);
	jQuery('.MainNav > li').each(function(i) {
		if(i == 0) {
			if(length == 5) {
				jQuery(this).width(liWidth[i] + exWidth + 0.45);
				jQuery(this).find("a > span").css("padding", "4px " + (12 + exWidth) + "px 0 0");
			}
			//fix issue #2183: Triangles are shifted vertically
			jQuery(this).find("a").css("background-position", (liWidth[i]-12-19)/2 + "px 100%");
		} else {
			if(length == 5) {
				jQuery(this).width(liWidth[i] + 2*exWidth + 0.9);
				jQuery(this).find("a > span").css("padding", "4px " + (12 + exWidth) + "px 0");
			}
		}
	});
		
	// end.
	var heigthCon03First = jQuery("#seperator_Con div.ADP_Con03_First").html() ? getHeight("#seperator_Con div.ADP_Con03_First") : 0;
    	var heigthCon03 = jQuery("#seperator_Con div.ADP_Con03").html() ? getHeight("#seperator_Con div.ADP_Con03") : 0;
    	var heigthCon03Last = jQuery("#seperator_Con div.ADP_Con03_Last").html() ? getHeight("#seperator_Con div.ADP_Con03_Last") : 0;
    	var heightCon03Max = Math.max(heigthCon03First, heigthCon03, heigthCon03Last);
	var position;
	if(heightCon03Max < 66 ) {
		position = "0px 2px";
	} else {
		position = "0px " + (heightCon03Max - 66)/2 +  "px";
	}
    
	jQuery("#seperator_Con .ADP_Con03 .ADP_Separate").css({'height': heightCon03Max + 'px'});
	jQuery("#seperator_Con .ADP_Con03 .ADP_Separate").animate({backgroundPosition: position });

	jQuery("#seperator_Con .ADP_Con03_Last .ADP_Separate").css({'height': heightCon03Max + 'px'});	
	jQuery("#seperator_Con .ADP_Con03_Last .ADP_Separate").animate({backgroundPosition: position });
	
	// fix min-height for  ie
	if(jQuery.browser.msie) {
		if(jQuery("#adp_content div.ADP_Min479").outerHeight() < 479) {
			jQuery("#adp_content div.ADP_Min479").css({'height' : 479 + 'px'});
		} else {
			jQuery("#adp_content div.ADP_Min479").css({'height' : 'auto'});
		}
		// fix issue #3086
		if (!jQuery("div.ADP_Nav_BoxTop").html()) {
			jQuery("div.ADP_Nav_BoxTop").css({'height' : 0 + 'px'});
		}
		// end
	}
	// end
	
	// fix full-content for country-index template
	if(jQuery("div.ADP_Countries_Index > div.ADP_Style01").length == 0) {
		jQuery("div.ADP_Countries_Index").css("padding", "0 15px");
	}
	// end
	
	// fix issue #2919: The height of the separator
	var heightBox2C1 = jQuery("div.ADP_Box2C1").html() ? getHeight("div.ADP_Box2C1") : 0;
	var heightBox2C2 = jQuery("div.ADP_Box2C2").html() ? getHeight("div.ADP_Box2C2") : 0;
	var max = heightBox2C1 > heightBox2C2 ? heightBox2C1 : heightBox2C2;
	jQuery("div.ADP_Box2C1 > div.ADP_Column_Separate").height(max);
	
	var heightBox4CFirst = jQuery("div.ADP_Box4CFirst").html() ? getHeight("div.ADP_Box4CFirst") : 0;
	var heightBox4C2 = jQuery("div.ADP_Box4C2").html() ? getHeight("div.ADP_Box4C2") : 0;
	var heightBox4C3 = jQuery("div.ADP_Box4C3").html() ? getHeight("div.ADP_Box4C3") : 0;
	var heightBox4C4 = jQuery("div.ADP_Box4C4").html() ? getHeight("div.ADP_Box4C4") : 0;
	
	max = Math.max(heightBox4CFirst, heightBox4C2, heightBox4C3, heightBox4C4);
	
	jQuery("div.ADP_Box4CFirst > div.ADP_Column_Separate").height(max);
	jQuery("div.ADP_Box4C2 > div.ADP_Column_Separate").height(max);
	jQuery("div.ADP_Box4C3 > div.ADP_Column_Separate").height(max);
	
	// end

	// fix issue #3176: [FO-Video Content] Layout is broken
	function getHeight(control) {
		var result = jQuery(control).outerHeight();
		jQuery(control + " div.Object").each(function(){
			var objectHeight = jQuery(this).attr("height") ? jQuery(this).attr("height") : 240;
			result += objectHeight - jQuery(this).outerHeight();
		});

		return result;
	}
	//end
});

FoOsmoz.flashVersion = "6.0.0";

swfobject.createOsmozSWF = function(id) {
	$fDiv = jQuery("#"  + id); 
	var fLinks = jQuery.parseJSON($fDiv.attr('fLinks') || "{}");
	
	var att = {'data':fLinks['data'], 'width':$fDiv.attr('fWidth'), 'height':$fDiv.attr('fHeight')};
	
	var flashvars = "";
	
	if (fLinks['xmlConfigPath'] != undefined) {
		flashvars += 'xmlConfigPath=' + fLinks['xmlConfigPath'] + '&';
	}
	
	if (fLinks['flv'] != undefined) {
		flashvars += 'flv=' + fLinks['flv'] + '&';
	}
	
	if (fLinks['startimage'] != undefined) {
		flashvars += 'startimage=' + fLinks['startimage'] + '&';
	}
	
	if (fLinks['soundFile'] != undefined) {
		flashvars += 'soundFile=' + fLinks['soundFile'] + '&';
	}
	
	if ($fDiv.attr('flashvars') != undefined) {
		flashvars += $fDiv.attr('moreVars') + '&';
	}
	
	if (flashvars != "") {
		flashvars = flashvars.substring(0, flashvars.length - 1);
	}
	
	
	
	var par = { 'flashvars':flashvars, 'wmode':"transparent", 'quality':'high', 'menu':'false'};
	
	swfobject.createSWF(att, par, id);
};

/**
 * This function used in video player flash to get the url of the page 
 * @return window.location
 */
function getWindowLocation(){
	return window.location.toString();
}
