$(document).ready(function(){
	
		//http://localhost/global/
		var baseUrl = window.location.toString();
		baseUrl = baseUrl.substr(0,30);		//alert(baseUrl);


	
	/* 
	 * Custome it....sandy will do the best thing in javascript style...
	 * 
	 */
	
		
		$("#navigation li").css({
			backgroundColor: "#66CCFF",
			borderRightColor:"#66CCFF",
			borderRightWidth:"2px",
			borderRightStyle:"solid"
		});
		
		$('#genPasswd').hide();
		
		$('#getPasswd').click(function(){
		
		$.get(baseUrl + "/getPass", function(data){
			$('#genPasswd').text(data).fadeIn('slow').css({
									backgroundColor:"#FF9FE7",
									borderColor:"#3EBDFF",
									borderWidth:"1px",
									borderStyle:"dashed"
									});					
								});
		});
	
		$('#imgBanner').innerfade({
						animationtype:'slide',
						speed: 1000,
						timeout: 5000,
						type: 'random_start',
						containerheight: '180px'
					});
		$('#showModal').hide();
		$('#button_show_product').toggle(function(){
			
				$('#showModal').show('fast');
				$.get(baseUrl + "/showHTMLProducts", function(data){
							$('#showModal').html(data);					
							});
				 
		},function(){
					$('#showModal').hide('slow');
		});
		
		
		//$('img[@id=imgTest').hover(function(){
				$('img[@class=imgTest]').each(function(i,a){
					
											
					/*
							$(a.id).hover(function(){
												alert('sss');
											},function(){
												
											});
					
				*/
		
			});
		
		
		
		function colorBlendCustom(html){
				$(html.elm).mouseover(function(){
					$(this).colorBlend([{
						param:html.param || "background-color",
						fromColor:html.frmColor || "#66CCFF",
						toColor:html.toColor || "#6666CC",
						cycles:1, 
						duration:1000}]);
						
						$(this).colorBlend([{
						param:"border-color",
						fromColor:"#66CCFF",
						toColor:"#CC3333",
						cycles:1, 
						duration:1000}]);
				
						$(this).colorBlend([{
						param:"font-color",
						fromColor:"#66CCFF",
						toColor:"random",
						cycles:1, 
						duration:1000}]);
			});
			
		}
			
		
   function textBigAnimation(e){
		 $(e).hover(function () { 
		 		$(this).animate({ fontSize:"15px" }); }, 
                 function () { 
				 $(this).animate({ fontSize:"1em" }); 
				 });
		
			
		}
	
	$('li.child').hide();
			
	

	
		
			
	 function loadContent(id) {
	
 	 
	$('#secondary-content').html("<img src='" + baseUrl + "/img/ajax-loader.gif'> Loading ...");

		
	$.get(baseUrl +'/category_product_show/'+ id , function(data) {
			
			$('#secondary-content').html(data);
			$('#dialog').hide();
			
		
			$(".baseproduct").click(function(w){
			   var index = $(".baseproduct").index(this);
			   var imagepath = $(".srcImage1:eq("+ index +")").val();
               var o1 = { elm:'#dialog',picturl:imagepath }
					showDialog(o1);
				});
			
			$(".spec").click(function(w){
				var index = $(".spec").index(this);
				var imagepath = $(".srcImage2:eq("+ index +")").val();
				var o1 = { elm:'#dialog',backgroundColor:"cyan",picturl:imagepath	}
					showDialog(o1);
			});

			$(".desc").click(function(w){
				var index = $(".desc").index(this);
				var imagepath = $(".srcImage3:eq("+ index +")").val();
				var o1 = {	elm:'#dialog',backgroundColor:"yellow",picturl:imagepath}
					showDialog(o1);
			});
						
		});
	
	};
	
	
	$('#parent').toggle(function(){
			$("li.child").show('slow');
		},function(){
			$("li.child").hide('fast');
		}
		);
	
	
	$("li.child a").click(function(i){
		var id = $(this).attr('href').replace(/^#/, "");
		loadContent(id);
	});
	
	
	
	$(".generalproduct").click(function(i){
		var id = $(this).attr('href').replace(/^#/, "");
		$("li.child").show('slow');
		loadContent(id);

	});
	
	if (location.hash) {
		
		loadContent(location.hash.replace(/^#/, ""));
	}
	
	
		

			
		//textBigAnimation("li.child");
		//textBigAnimation("#secondary-content p a");
		
		var oHtml = { elm:'#navigation li',toColor:'random'};
		colorBlendCustom(oHtml);
	
		var oHtml = { elm:'#secondary-content input,#inputSearch,#searchSubmit,textarea',param:'border-color',frmColor:'random',toColor:'random'};
		colorBlendCustom(oHtml);
	
	
		function showDialog(params){
			var windowSize = ___getPageSize();
			var pageScroll = ___getPageScroll();
			//arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			var center = pageScroll[0] + ( windowSize[1] / 2); 
			var top    = pageScroll[1] + ( windowSize[3] / 10); 
			
			var imageCreate = new Image();
			imageCreate.src = params.picturl;
			imageCreate.id = 'test';
			$('body').append('<div id="background_overlay"></div>');
			$('#background_overlay').css({
				backgroundColor:'black',
				position:"absolute",
				zIndex:"3199",
				opacity:0.5,	
				top:"0px",
				right:"0px",
				width:windowSize[0],
				height:windowSize[1]
			}).fadeIn('slow');
			
			
			
			$(params.elm || '#dialog').css({ 
					backgroundColor:params.backgroundColor || "#ccc",
					borderColor:params.borderColor || 'black',
					borderWidth:params.borderWidth || '2px',
					borderStyle:params.borderStyle ||'solid', 
					fontWeight:params.fontWeight|| "bolder",
					position:params.position || "absolute",
					top:params.top||top,
					right:params.right || center,
					width:params.width || "500px",
					height:params.height ||"500px",
					zIndex:params.zIndex|| "3200" 
				 });
				
				//$('#dialog').slideDown('slow').html('Temporary : Default Picture...<a id="cls" href="#">[close]</a>');
				$('#dialog').slideDown('slow').html("<img id='tempPict' src='" + params.picturl + "'>");
					

		
				$('#cls').click(function(){
					$('#dialog').slideUp(600);
					$('#background_overlay').fadeOut(function() { $('#background_overlay').remove(); });
				});
				$('#background_overlay').click(function(){
					$('#background_overlay').fadeOut(function() { $('#background_overlay').remove(); });
					$('#dialog').slideUp(600);
				});
		}
		
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
		
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ 
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { 
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		

 		$("#imageScroll").jMyCarousel({
		        visible: '8',
				 auto: true,
				 speed: 1100	
		    });


		 	
});



