﻿function addScript(url)
{
    var scriptTag=document.createElement("script");
    scriptTag.language="javascript";
    scriptTag.src=url;
    var hh = document.getElementsByTagName('head')[0];
    hh.appendChild(scriptTag);
    JQUERY_SCRIPT.push(url);
}
function addCss(url)
{
    var cssTag=document.createElement("link");
    cssTag.rel="stylesheet";
    cssTag.type="text/css";
    cssTag.href=url;
    var hh = document.getElementsByTagName('head')[0];
    hh.appendChild(cssTag);
    JQUERY_CSS.push(url);
}
/*-----Begin:Init-----*/
/*-----End:Init-----*/
function attachRound(selector)
{
	if(selector==null)
		selector=".roundable";
	if($(selector).html()!=null )
	{
		var listround=$(selector);
		for(var i=0;i<listround.length;i++)
		{
			var round=6;
			if(listround[i].round!=null)
				round=listround[i].round;
			alert(round);
			DD_roundies.addRule(listround[i],6,true);
		}
		
	}
}


function addclassHover(classname)
{
    $('.'+classname).mouseover(function()
    {
        $(this).addClass(classname+"_hover");
    });
    $('.'+classname).mouseout(function()
    {
        $(this).removeClass(classname+"_hover");
    });
}

function addFocus(classname,input_focus)
{

    if( $(classname)==null)
        return;
    $(classname).focus(function()
    {
        $(this).addClass(input_focus);
    });
    $(classname).blur(function()
    {
        $(this).removeClass(input_focus);
    });
}
function play(obj,idplayer)
{

	var file=$(obj).attr("file");
	playFlowplayer(idplayer,file);

}
function attackUI()
{

	addclassHover("bt_cart");
	addclassHover("bt_submit");
	addclassHover("search_bt");
	$("input:text").addClass("textbox");
	$("textarea").addClass("textarea");
	addFocus("input:text","textbox_focus");
	addFocus("textarea","textarea_focus");
	
}
function effect(selector,type,option)
{
	if(option==0)
		option=2000;
	//$(selector).css("display","none");
	eval("$(selector)."+type+"(option)");
	



}

function loadimage(obj)
{
		
	var imgbig=$(".imgbig");
	var aimgbig=$("#aimgbig");
	
	var img=$(obj).find("img")[0];
	imgbig.attr("src",img.src);
	aimgbig.attr("href",img.src);	
		
	return false;

}
function attackajaxmenu(selector,containerdisplay)
{

	var arraya=$(selector +" a");
	for(var i=0;i<arraya.length;i++)
	{
		var a=arraya[i];
		
		if($(a).attr("ajax")==0)
		{
			continue;
		}
		$(a).click(function()
		{
			var href=$(this).attr("href");	
			var thang=href.indexOf("#");
			
			if(thang!=-1)
				return true;
			$(containerdisplay).load(href,null,function()
			{
					
					attackajaxmenu("#uni-content-display","#uni-content-display");
					attackscroller();
					attackhighslide("scripts/highslide");
			});
			
			return false;
		});
	}
}


function expandMenuleft(selector)
{
		
		var listul=$(selector+" ul ul");
		listul.addClass("submenu");
		
		for(var i=0;i<listul.length;i++)
		{
			var ul=listul[i];
			if($(ul).find("li").html()==null)
				continue;
			var li=$(ul).parent();
			var a=li.find("a")[0];
			$(a).addClass("submenuheader");
			$(a).attr("itemid",i);
			$(a).attr("expand","false");
		
			
			
			$(li).hover(
			function()
			{
				var li=this;
				var ul=$(li).find("ul")[0];
				var ali=$(ul).children("li");
				var a=$("a",li)[0];
				for(var j=0;j<ali.length;j++)
				{
				
					if( $(ali[j]).find("a").attr("itemid") !=$(this).attr("itemid") )
					{
						$(ali[j]).children("ul").hide("slow");
						$(ali[j]).children("a").attr("expand","false");
						$(ali[j]).children("a").removeClass("active");
						
					}
				}
				var itemid=$(a).attr("itemid");
				//var ul=$(this).parent().find(".submenu")[0];


				$(this).attr("expand","false");
				$(ul).toggle("fast");
				$(a).addClass("active");

				
			},
			function()
			{
				var li=this;
				var ul=$(li).find("ul")[0];
				var a=$("a",li)[0];

				$(this).attr("expand","true");
				$(ul).toggle("slow");
				$(a).removeClass("active");


			})
			$(a).click(function()
			{
				return true;
			});
			
		}
				
		var location=window.location.href;
		var lista=$(selector+" a");
		
		for(var i=0;i<lista.length;i++)
		{
			var a=lista[i];
			if($(a).attr("href")==location)
			{
				a.id="current";
				var li=$(a).parent();
				var lista=new Array();
			
				while(true)
				{
					
					if(li[0].tagName==null)
						break;
				
					if(li[0].tagName=="LI")
					{
						var aactive=li.children("a");
						$(aactive).addClass("current");
						$(aactive).attr("expand",true);
						//li.children("ul").toggle("fast");//css("display","block");
					}
					li=$(li).parent();
					if(li.hasClass("scrollleft")==true)
						break;
				}
			}
		
		}


  

}

function expandMenu(selector)
{
		
		var listul=$(selector+" ul ul");
		listul.addClass("submenu");
		
		for(var i=0;i<listul.length;i++)
		{
			var ul=listul[i];
			if($(ul).find("li").html()==null)
				continue;
			var a=$( $(ul).parent() ).find("a")[0];
			$(a).addClass("submenuheader");
			$(a).attr("itemid",i);
			$(a).attr("expand","false");
		
			
			
			$(a).click(function()
			{
				
				var li=$(this).parent();
				var ul=$(li).parent();
				var ali=$(ul).children("li");
				for(var j=0;j<ali.length;j++)
				{
				
					if( $(ali[j]).find("a").attr("itemid") !=$(this).attr("itemid") )
					{
						$(ali[j]).children("a").removeClass("active");
						$(ali[j]).children("ul").hide("slow");
						$(ali[j]).children("a").attr("expand","false");
						
						
					}
			
				}
				
				

				var itemid=$(this).attr("itemid");
				var ul=$(this).parent().find(".submenu")[0];
				
				
				if($(this).attr("expand")=="true")
				{
					
					$(this).attr("expand","false");
					$(ul).toggle("slow");
				}
				else
				{	
					
					$(this).attr("expand","true");
					$(this).addClass("active");
					$(ul).toggle("slow");
					
				}
				
				return false;
				
				
			});
			
		}
				
		var location=window.location.href;
		var lista=$(selector+" a");
		for(var i=0;i<lista.length;i++)
		{
			var a=lista[i];
			if($(a).attr("href")==location)
			{
				a.id="current";
				var li=$(a).parent();
				var lista=new Array();
			
				while(true)
				{
					if(li[0]==null)
						break;
					if(li[0].tagName=="LI")
					{
						var aactive=li.children("a");
						$(aactive).addClass("active");
						$(aactive).attr("expand",true);
						li.children("ul").toggle("fast");//css("display","block");
					}
					li=$(li).parent();
					if(li.hasClass("scrollleft")==true)
						break;
				}
			}
		
		}


  

}

function blurSearch(obj)
{
	
	var text=$(obj).attr('value').replace(" ","");
	if(text=="")
	{
		
		obj.value=$(obj).attr('defaultvalue');
	}
}
function clickSearch(obj)
{
	
	if($(obj).attr('value')==$(obj).attr('defaultvalue'))
	{	

		obj.value=" ";
	}
}
function autoHeight1(selector1,selector2,selectorflash)
{

	var heightselector1=$(selector1).height();
	var heightselector2=$(selector2).height();
	if(selectorflash!=null)
		var heightselectorflash=$(selectorflash).height();
	heightselectorflash=heightselectorflash;
	var maxHeight=heightselector1> heightselector2+heightselectorflash? heightselector1:heightselector2+heightselectorflash;
	
	
	$(selector1).height(maxHeight);
	$(selector2).height(maxHeight-heightselectorflash);
}
function autoHeight(selector)
{
	
	var maxHeight=0;

	for(var i=0;i<selector.length;i++)
	{
		var height=$(selector[i]).height();
		maxHeight=height> maxHeight? height:maxHeight;
	}
	for(var i=0;i<selector.length;i++)
	{
		$(selector[i]).height(maxHeight);
	}
}
function showAccordionWindow(AccordionWindowDisplayItem)
{
		var item=$(AccordionWindowDisplayItem);
		var positionDisplay=$("#accordiondisplay");

		var idcurrent=window.accordioncurrent;


		var next=$(AccordionWindowDisplayItem);
		positionDisplay.append(next);
		
		var current=$(idcurrent);
		if(AccordionWindowDisplayItem!=idcurrent)
		{
		
			$("#accordionlist").append(current);
		}

		window.accordioncurrent=AccordionWindowDisplayItem;

	
}

function checkall(objthis)
{	
		if(objthis.checked==true)
		{
			$(".checkboxcart").attr("checked",true);
		}
		else
			$(".checkboxcart").attr("checked",false);
	
}
function attackend()
{
	$("ul").each(function()
	{

		$(this).find("li:last").addClass("end");
	});
}
function attacklistproduct()
{
	var items=$(".listproducts .items");
	var lenght=items.length;
	if(lenght%2==0)
	{	
		if(lenght>=2)
			$(items[lenght-2]).addClass("end");
	}
	if(lenght>=1)
		$(items[lenght-1]).addClass("end");
	
}
function attackcenter(selector)
{	
	if(selector==null)
	{
		$(".center").each(function(index,item)
		{
			$(item).css("float","left");
			$(item).width($(item).width());
			$(item).css("float","none");
			$(item).css("margin-left","auto")
			$(item).css("margin-right","auto")
		});
	}
	
}

function checkingIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}


function attackmeuimg(selector,location)
{
			var menu=$(selector);
			var li=$(selector +" li");
			for(var i=0;i<li.length;i++)
			{
				$(li[i]).addClass("item"+i);
				var urlimg=location+"menu"+i+".jpg";
				var a=$(li[i]).find("a");
				a.remove("img");
				var urlimghover=location+"menu"+i+"_active.jpg";
				if($(li[i]).hasClass("active")==true || $(li[i]).hasClass("current")==true )
					a.css("background-image","url('"+urlimghover+"')");
				else
					a.css("background-image","url('"+urlimg+"')");
				a.attr("urlimg",urlimg);
				a.attr("urlimghover",urlimghover);
				var img=document.createElement("img");
				img.src=urlimg;
				$(img).css("visibility","hidden");
				document.body.appendChild(img);
				var width=$(img).width();
				a.css("width",width);
				
				a.hover(
				function()
				{
			
					var urlimghover= $(this).attr("urlimghover");
					$(this).css("background-image","url('"+urlimghover+"')");
				},
				function()
				{
					var urlimg= $(this).attr("urlimg");
					$(this).css("background-image","url('"+urlimg+"')");

				});
			

			}		
			
}
function attackscroller(round)
{
	if(round==null)
		round=".round_m";
	if($(round).html()!=null)
	{
					$(round).scrollable({ 
					    size: 3,
						items: '.roundthumb',
						interval: 4000,
						loop: true, 
						speed: 100,
						clickable:false
					}).mousewheel().circular().autoscroll();
	}
}
function attackhighslide(urlhighslide)
{
	if(window.hs!=null)
	{
			hs.graphicsDir = urlhighslide+"/graphics/";
			hs.align = 'center';
			hs.transitions = ['expand', 'crossfade'];
			hs.outlineType = 'glossy-dark';
			hs.fadeInOut = true;
			hs.dimmingOpacity = 0.75;
			
			
			// Add the controlbar
			if (hs.addSlideshow) hs.addSlideshow({
				//slideshowGroup: 'group1',
				interval: 3000,
				repeat: false,
				useControls: true,
				fixedControls: true,
				overlayOptions: {
					opacity: 0.6,
					position: 'top center',
					hideOnMouseOut: true
				}
			});

	}


}
function temp()
{
		$("#manufacture").msDropDown({showIcon:false});
		
		$('#producttop').cycle({ 
		    fx:      'custom', 
		    cssBefore:{  
		        left: 232,   
		        top: -232,  
		        display: 'block' 
		    }, 
		    animIn: {  
		        left: 0, 
		        top: 0  
		    }, 
		    animOut: {  
		        left: 232,   
		        top: 232 
		    }, 
		    delay: -3000 
		});
		
		$('#productlikebest').cycle({ 
		    fx:     'scrollDown', 
		    easing: 'bounceout', 
		    delay:  -2000
		});	
		DD_roundies.addRule('.moduletable', '8px',true);	
}
function Effect5(selector)
{
		$(selector).css("display","block");
		$(selector).animate({opacity: "0.1", left: "+=420"}, 1200)
		.animate({opacity: "0.4", top: "+=160", height: "20", width: "20"}, "slow")
		.animate({opacity: "1", left: "20", height: "380", width: "420"}, "slow")
		.animate({top: "15"}, "fast")
		.slideUp()
		.slideDown("slow");
}
function Effect6(selector)
{
		$(selector).css("display","block");
		$(selector).animate({opacity: "0.1", left: "-=420"}, 1200)
		.animate({opacity: "0.4", top: "+=160", height: "20", width: "20"}, "slow")
		.animate({opacity: "1", left: "20", height: "380", width: "420"}, "slow")
		.animate({top: "15"}, "fast")
		.slideUp()
		.slideDown("slow");
}

function Effect2(selector)
{
	
	$(selector).css("display","block");
	$(selector).css("top","340px");
	$(selector ).animate({top:"-300px",queue:false,duration:1200},function()
	{
		$(selector ).animate({top:"410px",queue:false,duration:1200});
	});
	
}
function Effect1(selector)
{
	
	$(selector).css("display","block");
	$(selector).css("top","-1000px");

	$(selector ).animate({top:"0px",queue:false,duration:12000},function()
	{
		$(selector ).animate({top:"-1000px",queue:false,duration:12000});
	});

	
}

function Effect3(selector)
{

	$(selector).css("display","block");
	$(selector).css("left","425px");
	$(selector).animate({left:"-425px",queue:false,duration:1200},function()
	{
		$(selector).animate({left:"500px",queue:false,duration:1200});
	});
	
}
function Effect4(selector)
{

	$(selector).css("display","block");
	$(selector).css("left","-1000px");
	
	$(selector).animate({left:"0px",queue:false,duration:1200},function()
	{
		$(selector).animate({left:"-1000px",queue:false,duration:1200});
	});
	
	
}
function cycle1(selector)
{

	$(selector).cycle({ 
	    fx:    'shuffle', 
	    delay: -4000 
	});

}
function cycle2(selector)
{

	$(selector).cycle({ 
	    fx:      'custom', 
	    cssBefore: {  
	        left: 115,  
	        top:  115,  
	        width: 0,  
	        height: 0,  
	        opacity: 1, 
	        zIndex: 1 
	    }, 
	    animOut: {  
	        opacity: 0  
	    }, 
	    animIn: {  
	        left: 0,  
	        top: 0,  
	        width: 200,  
	        height: 200  
	    }, 
	    cssAfter: {  
	        zIndex: 0 
	    }, 
	    delay: -3000 
	});

}
function cycle3(selector)
{

	$(selector).cycle({ 
	    fx: 'custom', 
	    cssBefore: {  
	        top:  0, 
	        left: 0, 
	        width: 0, 
	        height: 0,  
	        zIndex: 1  
	    }, 
	    animIn:  {  
	        width: 200, 
	        height: 200  
	    }, 
	    animOut: {  
	        top:  200, 
	        left: 200, 
	        width: 0, 
	        height: 0 
	    }, 
	    cssAfter: {  
	        zIndex: 0  
	    }, 
	    delay: -1000 
	});
}
function cycleRand(selector)
{
	var rand=Math.random()*2;
	rand=Math.ceil(rand);
	var functionrecallback="cycle"+rand+"('"+selector+"')";
	eval(functionrecallback);
}
function SkinRand(skin,selector)
{
	var rand=Math.random()*6;

	rand=Math.ceil(rand);
	//rand=2;
	typeskin=rand;
	var div=document.createElement("div");
	div.id="effect"+typeskin;
	div.className="effect";
	
	var urlImage=skin+"images/bk_white"+typeskin+".png";
	
	var img=document.createElement("img");
	img.src=urlImage;
 	$(img).css("display","none");
 	$("#uni-content").append(img);
 	
 	$(img).ready(function()
 	{
 	
 		var repeat=$(img).width()>$(img).height()?"repeat-y":"repeat-x";
		if($(img).width()>$(img).height() )
		{
			$(div).width($(img).width());
			$(div).height(1000);
		}
		else
		{
			$(div).width(1000);
			$(div).height($(img).height());
		}
		$(div).css("background-image","url('"+urlImage+"')" );
		$(div).css("background-repeat",repeat );
		
		$("#uni-content").append(div);
		
		switch(rand)
		{
			case 5:
			case 6:
				var effect="Effect"+typeskin+"('"+selector+"')";	
				eval(effect);
				break;
			default:
				$(img).ready(function()
				{
					var effect="Effect"+typeskin+"('"+"#effect"+typeskin+"')";	
					eval(effect);
				});
	
		
		}
	
 	});
}

function autoload(boardtemplate)
{

	//expandMenuleft("#navmenu-h"); 
	attackcenter();
	attackend();
	attackUI();
}