function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
function changephoto(photoUrl) {
    $('#photomain img').attr('src',photoUrl);
}

$(function(){
	$("li:has(div)").hover(function(){
	    $(this).css("background-color",'white');
	    $(this).children("a").css("color",'black');
		var ul = $(this).children("div");
		var position = $(this).position();
		var maxWidth = $("#container").width();
        
        if (ul.width() > maxWidth-position.left) {
            ul.width(maxWidth-position.left-20); 
        }
                   
		var maxleft = (parseInt($("body").css("width"))/2)-322;
		if (ul.is(":animated")) {
			ul.stop()
			ul.css("height", "auto");
			ul.slideDown("normal");
		} else {
            ul.css("display", "none");
            ul.slideDown("normal");
		}
	},
		
	function(){
	  $(this).css("background-color",'transparent');
	  $(this).children("a").css("color",'white');
		var ul = $(this).children("div");
		if(ul.is(":animated")){
			ul.stop()
			.css("height", "auto")
			.slideUp("fast");
		}
		else{
			ul.slideUp("fast");
		}	
	});
});

var cmsIntervalId = 0;

function startPage () {

    var $elems = $("#promotions").children();
    var maxHeight= 450;
    $elems.each(function(){
        maxHeight = Math.max(maxHeight, $(this).height()); 
    });
    $elems.each(function(){
        $(this).height(maxHeight); 
    });    
    $("#promotions").height(maxHeight);
    cmsIntervalId = window.setInterval("slidePromotion()", 11500);
}

function movePromotions(step) {
    var slideWidth = 0;
    slideWidth = (-948*(step-1)) + 'px';
    if (slideWidth == '-0px') {
        slideWidth = '0px';
    }
    if (step == 1) {
        $('#promotion-step-1').css('background-color','#836231');
        $('#promotion-step-2').css('background-color','transparent');
    }

    if (step == 2) {
        $('#promotion-step-1').css('background-color','transparent');
        $('#promotion-step-2').css('background-color','#836231');
    }

    window.clearInterval(cmsIntervalId);
    cmsIntervalId = window.setInterval("slidePromotion()", 11500);

    animatePromotion(slideWidth);
}

function slidePromotion() {
    var slideWidth = 0;
    var currentMargin = $("#promotions table").css("marginLeft");
    if (currentMargin == '0px') {
        slideWidth = '-948px';
        $('#promotion-step-1').css('background-color','transparent');
        $('#promotion-step-2').css('background-color','#836231');
    }
    if (currentMargin == '-948px') {
        slideTo = '0px';
        $('#promotion-step-1').css('background-color','#836231');
        $('#promotion-step-2').css('background-color','transparent');
    }
    animatePromotion(slideWidth);
}

function animatePromotion(slideWidth) {
    $("#promotions table").animate({ 
        marginLeft: slideWidth
    }, 1500 );
}
