function gup( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

(function ($) {
// VERTICALLY ALIGN FUNCTION
	$.fn.vAlignM = function() {
		return this.each(function(i){
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = (ph - ah) / 2;
			$(this).css('margin-top', mh);
		});
	};
})(jQuery);

jQuery.fn.equalizeCols = function(){
	var height = 0;
	return this.css("height","auto").each(function(){
		height = Math.max( height, jQuery(this).outerHeight() );
	}).css("height", height);
};

(function ($) {
// VERTICALLY ALIGN FUNCTION
	$.fn.vAlignP = function() {
		return this.each(function(i){
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = (ph - ah) / 2;
			$(this).css('padding-top', mh);
		});
	};
})(jQuery);



jQuery.fn.equalizeCols = function(){
	var height = 0;
	return this.css("height","auto").each(function(){
	height = Math.max( height, jQuery(this).outerHeight() );
	}).css("height", height);
};

var MarginObjectContainer = 0;
var ObjectPerCol = 1;
var ColPerPage = 1;
var ObjectPerPage = 1;
var ObjectContainerWidth = 0;
var MaxAllowedColID = 0;
var ObjectColID = 0;
var MaxContentFrameSize = 0;

function ColScroller() {
	
	ObjectContainerWidth = parseInt($('.ObjectContainer').width()) + MarginObjectContainer;
	
	ColPerPage = Math.floor(MaxContentFrameSize / ObjectContainerWidth);
	ObjectPerPage = ObjectPerCol * ColPerPage;
	
	var ContentFrameWidth = ObjectContainerWidth * ColPerPage;
	
	$('div.ContentFrame').width(ContentFrameWidth);

	if (NoOfObjects <= ObjectPerPage) {
		$('.ContentScrollerContainer').hide();
	}
	
	MaxAllowedColID = Math.ceil(NoOfObjects / ObjectPerCol) - ColPerPage;
	ObjectColID = 0;
	
	$('.ScrollerLeft').click( function (ev) {
		if (ObjectColID > 0)
			ObjectColID--;
		var LeftOffset = ObjectColID * ObjectContainerWidth * -1;
		
		$('div.ContentScrollArea').animate({'left': LeftOffset});
		ev.preventDefault();
	});
	$('.ScrollerRight').click( function (ev) {
		if (ObjectColID < MaxAllowedColID)
			ObjectColID++;
		var LeftOffset = ObjectColID * ObjectContainerWidth * -1;
		
		$('div.ContentScrollArea').animate({'left': LeftOffset});
		ev.preventDefault();
	});	
	
}

$(document).ready(function(){
	$('a.MySubmitButton').click( function(ev) {
		ev.preventDefault();
		if ($(this).attr('target') != '') {
			$('#' + $(this).attr('target')).submit();
		}
	});

	$("#Logo").hover(
		function(){
			$('#Logo2').fadeIn("fast");
		},
		function(){
			$('#Logo2').fadeOut("fast");
		}		
	);
	
	
	if (MyJS == 'FrontPage') {
		$("#slider").easySlider({
			auto: true,
			continuous: true 
		});
	}
	else if (MyJS == 'ProductList') {
		$('#ProductListBanner img.AnimateImg').animate({
			marginLeft: '-=100',
			marginTop: '-=0',
			width: '984px'
			}, 5000, function() {

				// Animation complete.
				$('#ProductListBanner img.ProductListBannerTitle').fadeOut("slow");
				$(this).fadeOut("slow", function() {
					
					$('#ProductListBanner img.ProductListBannerBg').fadeOut("slow");
					$('#ProductListBanner img.AnimateImg2').fadeIn("slow");
					$('#ProductListBanner img.AnimateText2').fadeIn("slow");
					/*
					$('#ProductListBanner img').css("width", "884px");
					$('#ProductListBanner img').css("margin-left", "0px");
					$('#ProductListBanner img').fadeIn("slow");
					*/
				});

			});
		
		$('div.ProductListProductContainer').hover(
			function () {
				$('img.ProductListPhoto1', this).hide();
				$('img.ProductListPhoto2', this).show();
			},
			function () {
				$('img.ProductListPhoto1', this).show();
				$('img.ProductListPhoto2', this).hide();
			}
		);		
	}
	else if (MyJS == 'TVC') {
		MarginObjectContainer = 16;
		ColPerRow = 1;
		MaxContentFrameSize = 830;
		ColScroller();		
	}
	else if (MyJS == 'AdCampaign') {
		MarginObjectContainer = 0;
		ColPerRow = 1;
		MaxContentFrameSize = 933;
		ColScroller();		
	}
	else if (MyJS == 'MediaClipping') {
		MarginObjectContainer = 0;
		ColPerRow = 1;
		MaxContentFrameSize = 336;
		ColScroller();
		
		$('div.MediaClippingPhotoContainer a').click(
			function (e) {
				e.preventDefault();
				$('#MediaClippingBigPhotoContainer img').hide();
				
				var newsrc = $(this).attr('data-big_src');
				var newdesc = $(this).attr('media-desc');
				
				var img = new Image();
				$(img).load(function () {
					$('#MediaClippingBigPhotoContainer img').attr('src', newsrc);
					$('#MediaClippingBigPhotoContainer img').fadeIn();
				}).attr('src', newsrc);
				$('#MediaClippingTextContainer').html(newdesc);
//				$('#MediaClippingBigPhotoContainer img').hide().attr('src', $(this).attr('data-big_src')).fadeIn();
			}
		);
	}
	else if (MyJS == 'Event') {
		MarginObjectContainer = 12;
		ColPerRow = 1;
		MaxContentFrameSize = 900;
		ColScroller();
		
		$('div.EventEventListPhotoContainer a').click(
			function (e) {
				e.preventDefault();
				$('#EventBigPhotoContainer img').hide();
				
				var newsrc = $(this).attr('data-big_src');
				var img = new Image();
				$(img).load(function () {
					$('#EventBigPhotoContainer img').attr('src', newsrc);
					$('#EventBigPhotoContainer img').fadeIn();
				}).attr('src', newsrc);
//				$('#MediaClippingBigPhotoContainer img').hide().attr('src', $(this).attr('data-big_src')).fadeIn();
			}
		);
	}
	else if (MyJS == 'ProductDetails') {
		MarginObjectContainer = 4;
		ColPerRow = 1;
		MaxContentFrameSize = 780;
		ColScroller();

		$('div.ProductDetailsProductListProductPhoto').mousemove(function(e){
			$('div.ProductDetailsProductListProductPhotoMouseOver').css({'left' : e.pageX + 20, 'top' : e.pageY + 20});		
		});
		
		$('div.ProductDetailsProductListProductPhoto').hover(
			function () {
				$('div.ProductDetailsProductListProductPhotoMouseOver').text($('img', this).attr('alt'));
				$('div.ProductDetailsProductListProductPhotoMouseOver').show();
				
			},
			function () {
				$('div.ProductDetailsProductListProductPhotoMouseOver').hide();
			}
		);
		
		$('div.ProductDetailsProductListProductPhoto img').mouseover(function(){
			$(this).css("width", "110px");
			
			$(this).css("marginTop", "-15px");
			$(this).css("marginLeft", "-15px");
			
		});
		
		$('div.ProductDetailsProductListProductPhoto img').mouseout(function(){
			$(this).css("width", "80px");
			$(this).css("marginTop", "0px");
			$(this).css("marginLeft", "0px");
			
		});
		
		
		
	}
});
