//tab effects

var TabbedContent = {
	init: function() {
		
		
var val = location.querystring["tab"];

$(".tab_item").css({'color': '#ffffff'});
	if(val != undefined)
		{			
			//var currentId = $("#element").attr("sdesk"); 
			
			$('#'+val).css({'color': '#ffffff'});
			var background = $('#'+val).parent().find(".moving_bg");
			var posBg = parseInt($('#'+val).position()['left']);
		
			//alert(posBg);
			if (posBg >540 && posBg <640)
				{
					
					document.getElementById("hdnmenu").value="2";
					$(".tab_item").parent().parent().find(".tab_item").stop().animate({
						left: -137
					}, {
						duration: 500
					});
					//alert($('#'+val).position()['left']);
					$(background).stop().animate({
						left: 411
					}, {
						duration: 500
					});			
					
				}
			else if (posBg >640  )
				{
					
					if (posBg >=822)
					{
					fnAnimation("3",-411,411);
					}
					else
					{
						fnAnimation("4",-274,411);
					}
					
				}
			/*else if (posBg >=685 )
				{
				
					document.getElementById("hdnmenu").value="4";	
					$(".tab_item").parent().parent().find(".tab_item").stop().animate({
						left: -274
					}, {
						duration: 500
					});
					
					$(background).stop().animate({
						left: 411
					}, {
						duration: 500
					});
				}
				*/
			else
				{
				
					$(background).stop().animate({
							left: $('#'+val).position()['left']
						}, {
							duration: 500
						});
				}
			TabbedContent.slideContent($('#'+val));
			$('#'+val).css({'color': '#000000'});		
		}
		function fnAnimation(hdnValue,fLeft,sLeft)
		{
			document.getElementById("hdnmenu").value=hdnValue;	
						$(".tab_item").parent().parent().find(".tab_item").stop().animate({
							left: fLeft
						}, {
							duration: 500
						});
						
						$(background).stop().animate({
							left: sLeft
						}, {
							duration: 500
						});
		}
		//Menu next click event coding starts here...
		$('#menuNext').click(function() {
						
						
			var obj = document.getElementById("hdnmenu");
			var objCnt = document.getElementById("hdnmenucount");
			var	 pos = $(".tab_item").parent().find(".moving_bg").position()['left'];
			var Cnt = parseInt(objCnt.value) - parseInt(obj.value)
			//alert(obj.value);
			if (Cnt >=4)
			{
				var background = $(".tab_item").parent().find(".moving_bg");
				$(".tab_item").parent().parent().find(".tab_item").stop().animate({
					left: "-" + parseInt(obj.value) * 137
					
				}, {
					duration: 500
				});
				if (pos >0 )
				{
						$(background).stop().animate({
						left: $(".tab_item").parent().find(".moving_bg").position()['left']  - 137
					}, {
						duration: 500
					});
						
				}				
				
				
				if (pos == 0 && obj.value ==1)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-539px"
						}, {
							duration: 500
						});
					}
					
					if (pos == 0 && obj.value ==2)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-1078px"
						}, {
							duration: 500
						});
					}
					if (pos == 0 && obj.value ==3)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-1617px"
						}, {
							duration: 500
						});
					}
					obj.value = parseInt(obj.value) + 1;
			}
		});
		//Menu next click event coding ends here..
		
		//Menu previous click event coding starts here..
		$('#menuPrev').click(function() {
								   
			var obj = document.getElementById("hdnmenu");
			var objCnt = document.getElementById("hdnmenucount");
			var	 pos = $(".tab_item").parent().find(".moving_bg").position()['left'];
			
			if (obj.value  >= 2 && obj.value <=4)
			{
				obj.value = parseInt(obj.value) - 1;
				$(".tab_item").parent().parent().find(".tab_item").stop().animate({
					left: "-"+ (parseInt(obj.value)-1)  * 137
					
				}, {
					duration: 500
				});
				
					if (pos == 411 && obj.value ==1)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-1617px"
						}, {
							duration: 500
						});
					}
					if (pos == 411 && obj.value ==2)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-2156px"
						}, {
							duration: 500
						});
					}
					if (pos == 411 && obj.value ==3)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-2695px"
						}, {
							duration: 500
						});
					}
					if (pos == 411 && obj.value ==4)
					{
						$(".tab_item").parent().parent().find(".tabslider").stop().animate({
							marginLeft: "-3234px"
						}, {
							duration: 500
						});
					}
		
				if ($(".tab_item").parent().find(".moving_bg").position()['left'] < 410)
				{
						$(background).stop().animate({
						left: $(".tab_item").parent().find(".moving_bg").position()['left']  + 137
					}, {
						duration: 500
					});
						
						
			//$(".tab_item").css({'color': '#000000'});
				}
				
			}
		});
		//Menu previous click event coding ends here..
		
		$(".tab_item").mouseover(function() {
		
		$(this).parent().find(".tab_item").css({'color': '#ffffff'});
			var background = $(this).parent().find(".moving_bg");
			
			$(background).stop().animate({
				left: $(this).position()['left']
			}, {
				duration: 500
			});
			
			TabbedContent.slideContent($(this));
			$(this).css({'color': '#000000'});

		});		
	},
	
	slideContent: function(obj) {
		
		var margin = $(obj).parent().parent().find(".slide_content").width();
		margin = margin * ($(obj).prevAll().size() - 1);
		margin = margin * -1;
		
		$(obj).parent().parent().find(".tabslider").stop().animate({
			marginLeft: margin + "px"
		}, {
			duration: 500
		});
	}
}

$(document).ready(function() {
						   
	TabbedContent.init();
});

location.querystring = (function() {

    // The return is a collection of key/value pairs

    var queryStringDictionary = {};

    // Gets the query string, starts with '?'

    var querystring = decodeURI(location.search);

    // document.location.search is empty if no query string

    if (!querystring) {
        return {};
    }

    // Remove the '?' via substring(1)

    querystring = querystring.substring(1);

    // '&' seperates key/value pairs

    var pairs = querystring.split("&");

    // Load the key/values of the return collection

    for (var i = 0; i < pairs.length; i++) {
        var keyValuePair = pairs[i].split("=");
        queryStringDictionary[keyValuePair[0]]
                = keyValuePair[1];
    }

    // toString() returns the key/value pairs concatenated

    queryStringDictionary.toString = function() {

        if (queryStringDictionary.length == 0) {
            return "";
        }

        var toString = "?";

        for (var key in queryStringDictionary) {
            toString += key + "=" +
                queryStringDictionary[key];
        }

        return toString;
    };

    // Return the key/value dictionary

    return queryStringDictionary;
})();

