  //jquery.CreativePlugins.js   
  
  //last update: 05/10/10

/*  

  
****Plugins description

===> AutoOver 
      {when cerating a menu with links, automatically sets the link of class 'linksClass' of the current page to its rollover state (imageName.ext becomes imageName_over.ext) also removes the 'className' from the link to prevent any potential rollover effects}
    [
      $(linksClass).AutoOver({className: 'linksClass'});
    ]
    
    
===> ColorOverlay
      {creates an overlay above 'linksClass' of color 'color' and 'z-index 'zIndex'. The overlay has an opacity of 'opacityDefault' and fades on rollover to opacity 'opacityFadeTo' in 'duration' milliseconds} 
    [
      $(linksClass).ColorOverlay({color:'white', opacityDefault:0, opacityFadeTo:0.2, duration:350, zIndex:1});
    ]      
    
    
===> DeepLinking
      {creates a deep linking architecture from code contained in a single file. DeepLinking can have unlimited depth (sub contents)}
    [
      $('.pageClass').DeepLinking({DLclass:'pageClass'});
    
    structure:
      <div class="page" id="page01" style="display:none;" >
        <a class="deepLink" href="page=02">page2</a> 
      </div>  
      <div class="page" id="page02" style="display:none;" >
        <a class="deepLink" href="page=01">page2</a> 
      </div>    
    ]
    
    
===> FadeOpacity
      {fades image in 'duration' milliseconds to 'opacity' opacity on 'roClass' mouseOver}
    [                                                     
      $(roClass).FadeOpacity({opacity:0.5, duration:305}); //default values
    ]
    
    
===> FadeRo
      {fades between two images (imageName.ext and imageName_over.ext) in 'speed' milliseconds on 'roClass' mouseOver}
    [
      $(roClass).FadeRo({speed:500}); //default value 
    ]
    
    
===> HorizontalScroll 
      {Scrolls the content of 'inputDiv' div horizontally of 'numOfPx' pixels each 'interval' milliseconds using 'leftBtn' and 'rightBtn' buttons}
    [		
      $('#slider').HorizontalScroll({inputDiv:'#slider', leftBtn:'.left', rightBtn:'.right', interval:1, numOfPx:2}); //default values 
    ]
    
    
===> ImageButton
      {switches between two images (imageName.ext and imageName_over.ext) on 'roClass' mouseOver}
      [
        $(roClass).ImageButton();
      ]
      
===> MouseScroll
      {Scrolls the content of 'sliderClass' div in 'type' direction (can be 'horizontal', 'vertical' or 'both') on mouseMove between 'stopSection' sections at a frame rate of 'frameRate' in 'speed' speed}
      [
        $(sliderClass).mousescroll({speed:5, stopSection:150, type: 'horizontal', frameRate:90}); //default values
      ]
      
      
===> TimedGallery
      {automatically fades images inside '#gallery' list in 'speed' milliseconds every 'interval' milliseconds, pausing on rollover if 'pause'}
      [
        $('#gallery').timedgallery({speed: 300, pause: true, interval: 3000}); //default values
      
      structure:
        <ul id="gallery">
      	  <li><img src="images/01.jpg" /></li>
      	  <li><img src="images/02.jpg" /></li>
      	</ul>
		  ]
		  
		  
===> VerticalScroll
      {Scrolls the content of 'inputDiv' div vertically of 'numOfPx' pixels each 'interval' milliseconds using 'upBtn' and 'downBtn' buttons}
      [        
        $('#slider').HorizontalScroll({inputDiv:'#slider', upBtn:'.up', downBtn:'.down', interval:1, numOfPx:2}); //default values      
      ]
    


****Functions description

===> function GetParameters(href)
      {returns an array of parameters contained in "href"}
    [
      array = GetParameters(http://www.asos.com/pgehtml.aspx?cid=11128&page=02)
      returns:
        array[cid] = 11128
        array[page] = 02
    ]
    
    
*/  
  
  
  
/*** Plugins ***/




////AutoOver
  (function($)
  {   
    $.fn.AutoOver = function(opt)
    { 
      var defaults = {
          className:''
      };
      
      var options = $.extend(defaults, opt);
         
      var currentURL = window.location.href; 
      var parameters = GetParameters(document.location.href);
      var currentCid = parameters['cid'];
      
      var className = options.className;
      
      $(this).each(function()
      {
        var currentRO = $(this).attr('href');
        var parameters = GetParameters(currentRO);
        
        if(currentCid && currentCid == parameters['cid'])
        {
          var src = $(this).find('img').attr('src');
          aSrc = src.split('.');
          var srcBase = '';
          for(i=0;i<aSrc.length-1;i++)
          {
            srcBase += aSrc[i]+'.';
          }
          srcBase = srcBase.slice(0,srcBase.length-1);
          $(this).find('img').attr('src',srcBase+"_over."+aSrc[aSrc.length-1]);;
          $(this).removeClass(className);      
        }
      });
    }
  })(jQuery);
  
  
  
  
////ColorOverlay    
  (function($)
  {
    $.fn.ColorOverlay = function(opt)
    {   
        var defaults = {
          color:'white',
          opacityDefault:0,     
          opacityFadeTo:0.2,
          duration:350,
          zIndex:1
        };
        
        var options = $.extend(defaults, opt);
        
        //generate a random key to keep the divs unique within each plugin call
        var randomKey=Math.floor(Math.random()*100001);
        
        //for each element of targeted class
        $(this).each(function()
        {
          //create a div overlay matching target position and dimentions using the key
          $(this).parent().append("<div class='divColorOverlayJQuery"+randomKey+"' id='"+$(this).attr('href')+"' style='width:"+$(this).width()+"px; height:"+$(this).height()+"px; left:"+$(this).position().left+"px; top:"+$(this).position().top+"px;'>&nbsp;</div>");
        });
        
        //for each created overlays containing the key, set position to absolute and assign 'zIndex' and 'opacityDefault' parameters
        $('.divColorOverlayJQuery'+randomKey).css({'position':'absolute','zIndex':options.zIndex,'backgroundColor':options.color,'opacity':options.opacityDefault,'cursor':'pointer'}).hover(
        function()
        {
          //on rollover, fade to 'opacityFadeTo'
          $(this).stop(true).animate({'opacity':options.opacityFadeTo},350);
        },
        function()
        {   
          //on rollout, fade to 'opacityDefault'                     
          $(this).stop(true).animate({'opacity':options.opacityDefault},350);
        }).click(                                             
        function()
        {
          //redirect to id value onclick
          window.location.href = $(this).attr('id');
        });
    };
  })(jQuery);
  
  
  
////DeepLinking
  (function($)
  {
    $.fn.DeepLinking = function(opt)
    {   
      var defaults = {DLclass:""};
      var options = $.extend(defaults, opt);  
      //get deep linking container class name
      var DLparameter = options.DLclass+"=";
        
      var currentURL = window.location.href;
      
      //if we are currently inside a deep linked page and the deep link parameter is the first one 
      if(currentURL.indexOf(DLparameter) != -1) 
      {                       
        //split current URL at deep linking parameter                                 
        var currentURL = currentURL.split(DLparameter);
        //check if there are other parameters after the index of the deep linking parameter
        var postCurrentURL = currentURL[1];  
        //if there are, save them in a variable else empty the variable
        if(postCurrentURL.indexOf('&') != -1)
          postCurrentURL = postCurrentURL.substring(postCurrentURL.indexOf('&'), postCurrentURL.length); 
        else
          postCurrentURL = '';
        //get the current url without the deep linking index  
        currentURL = currentURL[0]+DLparameter;
        //select the deep links anchors
        $('.'+options.DLclass+'> .deepLink').each(function()
        {              
          //get href and isolate index value
          var thisIndex = $(this).attr('href').split(DLparameter);
          thisIndex = thisIndex[1];    
          //modify href to include the current URL, the specified index and the other parameters
          $(this).attr('href',currentURL+thisIndex+postCurrentURL);
        });
      }
      
      //if we are not currentlu inside a deep linked page, but there are other parameters                                                             
      else if( currentURL.indexOf("?") != -1) 
      {
        //select the deep links anchors
        $('.'+options.DLclass+'> .deepLink').each(function()
        {               
          //get href and isolate index value
          var thisIndex = $(this).attr('href').split(DLparameter);
          thisIndex = thisIndex[1];      
          //add index value to href
          $(this).attr('href',currentURL+'&'+DLparameter+thisIndex);
        });
      }
      
      //if we are not currently inside a deep linked page and there are no parameters
      else             
      {                       
        //select the deep links anchors
        $('.'+options.DLclass+'> .deepLink').each(function()
        {                
          //get href and isolate index value
          var thisIndex = $(this).attr('href').split(DLparameter);
          thisIndex = thisIndex[1];        
          //add index value to href
          $(this).attr('href',currentURL+'?'+DLparameter+thisIndex);
        });
      }
      
      //get deep link parameter
      var parameters = GetParameters(document.location.href);
      var currentParam = parameters[options.DLclass];
      
      //if there is no current deep link parameter, show the first element
      if(!currentParam)
      {
        $('.'+options.DLclass+':first').fadeIn();   
      }
      
      //else show relevant elements  
      else
      { 
        $('.'+options.DLclass).each(function()
        {
          if($(this).attr('id') == options.DLclass+currentParam)
            $(this).fadeIn();
        }); 
      }        
    };
  })(jQuery);
  
  
  
  
////FadeOpacity
  (function($)
  {
    $.fn.FadeOpacity = function(opt)
    {   
        var defaults = {
            opacity:0.5,
            duration:305
        };
        
        var options = $.extend(defaults, opt);
        
        $(this).mouseover(function() 
        {
          //animate target to opacity 'opacity' in 'duration' milliseconds
          $(this).stop(true).animate({opacity:options.opacity},{duration:options.duration});
        });   
        
        $(this).mouseout(function() 
        {                                                   
          //animate target to opacity 1 in 'duration' milliseconds
          $(this).stop(true).animate({opacity:1},{duration:options.duration});
        });
    };
  })(jQuery);
  
  
  
  
////FadeRo  
  (function($)
  {
    $.fn.FadeRo = function(opt) 
    {
      var defaults = {
        speed: 500
      }
      
      var options = $.extend(defaults, opt);
      var speed = options.speed;       
      
      $(this).hover(function() 
      {   
        thisImage = $(this).find("img");      
        var thisSrc = thisImage.attr("src").split('/');
        var preImgSrc = "";
        for(i=0; i<thisSrc.length-1; i++)
        {
          preImgSrc += thisSrc[i]+'/';
        }
        var imgSrc = thisSrc[thisSrc.length-1].split('.');                    
            
        overSrc = preImgSrc+imgSrc[0]+"_over."+imgSrc[1];
        
        if($(this).find("img.overImg").length == 0)
        {
          $(document.createElement("img")).attr({ src: overSrc}).css({"position":"absolute","left":0,"top":0,"opacity":0}).addClass("overImg").appendTo($(this));
        }
          
        $(this).find("img.overImg").stop(true).animate({"opacity":"1"},speed, function(){$(this).find("img:first").css({"opacity":"0"})});   
      },
      function()
      {
        $(this).find("img.overImg").stop(true).animate({"opacity":"0"},speed, function(){$(this).find("img:first").css({"opacity":"1"})});
      });
    };
  })(jQuery);  
  
  
  
  
////HorizontalScroll
  (function($)
  {
    $.fn.HorizontalScroll = function(opt)
    {
      var defaults = {
        inputDiv: "#slider",
        leftBtn: ".left",
        rightBtn: ".right",
        interval: 1,
        numOfPx: 2		
      };
        
    	var options = $.extend(defaults, opt);
        inputDiv = options.inputDiv;
        leftBtn = options.leftBtn;
        rightBtn = options.rightBtn;
        interval = options.interval;
        numOfPx = options.numOfPx;
    	
    	var move = false;
      var timer;
      
      $(leftBtn).hover(function() 
      {
        move = "left";
      },
      function() 
      {
        clearInterval(timer);
    		move = false;
    	});
      
      $(rightBtn).hover(function() 
      {
        move = "right";
      },
      function() 
      {
        clearInterval(timer);
    		move = false;
    	});
      
      timer = setInterval(animateDiv, interval);
      
      function animateDiv() 
      {
        if (move == "left")
          $(inputDiv).attr('scrollLeft',$(inputDiv).attr('scrollLeft') - numOfPx);
        else if (move == "right")
          $(inputDiv).attr('scrollLeft',$(inputDiv).attr('scrollLeft') + numOfPx);
        else
          return null;
      }	
    }
  })(jQuery); 
  
  
  
  
////ImageButton
  (function($)
  {
    $.fn.ImageButton = function()
    {
      var currentImg = $(this).find('img');
      $(this).find('img').css({cursor: 'pointer'});
      
      $(currentImg).hover(function()
      {             
        var thisSrc = this.src.split('/');
        var preImgSrc = "";
        for(i=0; i<thisSrc.length-1; i++)
        {
          preImgSrc += thisSrc[i]+'/';
        }
        var imgSrc = thisSrc[thisSrc.length-1].split('.');
        
        $(this).attr("src",preImgSrc+imgSrc[0]+"_over."+imgSrc[1]);
      },
      function() 
      {             
        var thisSrc = this.src.split('/');
        var preImgSrc = "";
        for(i=0; i<thisSrc.length-1; i++)
        {
          preImgSrc += thisSrc[i]+'/';
        }
        var imgSrc = thisSrc[thisSrc.length-1].split('.');
        
        $(this).attr("src",preImgSrc+imgSrc[0].slice(0, -5)+"."+imgSrc[1]);
      });
    };
  })(jQuery);
  
  
  
  
////MouseScroll
  (function($)
  {
    var type;
    var speed;
    var stopSection;
    var frameRate;
    var conWidth;
    var conHeight;
  	
    $.fn.mousescroll = function(opt)
    {
        var defaults = {
        speed: 5,
    		stopSection: 150,
    		type: "horizontal",
    		frameRate: 90
        };
        
    	var options = $.extend(defaults, opt);
      speed = options.speed;
    	stopSection = options.stopSection;
    	type = options.direction;
    	frameRate = options.frameRate;
    	var inputDiv = $(this);
    	
    	var move = false;
    	
    	$(this).bind("mouseenter", function(e)
      {
    		move = true;
    	});
    	
    	$(this).bind("mouseleave", function(e)
      {
    		move = false;
    	});
    	
    	$(this).css({overflow: 'hidden'});
    	conWidth = parseInt($(this).css('width'));
    	conHeight = parseInt($(this).css('height'));
    	
    	var currentY;
    	var currentX;
    	
    	$(this).mousemove(function(e)
      {
    		currentY = e.pageY - $(this).offset().top;
        currentX = e.pageX - $(this).offset().left;
    	});
    	
    	var lessThanY = parseInt($(this).css('height'))/2 - stopSection/2;
    	var moreThanY = parseInt($(this).css('height'))/2 + stopSection/2;
    	var lessThanX = parseInt($(this).css('width'))/2 - stopSection;
    	var moreThanX = parseInt($(this).css('width'))/2 + stopSection;
    	
    	function enterFrame()
      {
    		if(move){
    			if(currentX < lessThanX)
    				scrollContainerX(-1, (lessThanX - currentX)/lessThanX);
    			else if(currentX > moreThanX)
    				scrollContainerX(1, (currentX - moreThanX)/(conWidth - moreThanX));
    			else
    				scrollContainerX(0, 0);
    			
    			if(currentY < lessThanY)
    				scrollContainerY(-1, (lessThanY - currentY)/lessThanY);
    			else if(currentY > moreThanY)
    				scrollContainerY(1, (currentY - moreThanY)/(conHeight - moreThanY));
    			else
    				scrollContainerY(0, 0);
    		}
    	}
    	var timer = setInterval(enterFrame, 1000/frameRate);
    	
    	function scrollContainerY(direction, acc)
      {
    		if(type == "vertical" || type == "both")
    			inputDiv.attr('scrollTop', inputDiv.attr('scrollTop') + (direction * speed)*acc);
    	}
    	
    	function scrollContainerX(direction, acc)
      {
    		if(type == "horizontal" || type == "both")
    			inputDiv.attr('scrollLeft',inputDiv.attr('scrollLeft') + (direction * speed)*acc);
    	}
    }
  })(jQuery);
  
  
  
  
////TimedGallery
  (function($)
  {
  	var images;
    var speed;
    var currentPage;
  	var over;
  	
    $.fn.timedgallery = function(opt)
    {
        var defaults = {
            speed: 300,
    		pause: true,
    		interval: 3000
        };
    	
    	images = $(this).children();
        
    	var options = $.extend(defaults, opt);
        speed = options.speed;
    	interval = options.interval;
    	pause = options.pause;
    	
    	$(images).each(function()
      {
    		$(this).css({position: "absolute", top: 0, left: 0});
    		$(this).hide();
    	});
    	
    	changePage(0);
    	
    	var timer = setInterval(nextPage, interval);
    	
    	$(this).hover
      (
    		function()
        {
    			over = true;
    		},
    		function()
        {
    			over = false;
    		}
    	)
    };
  
    function nextPage()
    {
    	if(currentPage + 1 > $(images).length - 1)
    		changePage(0);
    	else
    		changePage(currentPage + 1);
    }
  
    function changePage(image)
    {
    	if(!pause || !over)
      {
    		$(images).each(function()
        {
    			$(this).fadeOut(speed);
    		});
    		$(images[image]).fadeIn(speed);
    		
    		currentPage = image;
    	}
    }
  
  })(jQuery); 
  
  
  
  
////VerticalScroll
  (function($)
  {
    $.fn.VerticalScroll = function(opt)
    {
      var defaults = {
        inputDiv: "#slider",
        upBtn: ".up",
        downBtn: ".down",
        interval: 1,
        numOfPx: 2		
      };
      
      var options = $.extend(defaults, opt);
        inputDiv = options.inputDiv;
        upBtn = options.upBtn;
        downBtn = options.downBtn;
        interval = options.interval;
        numOfPx = options.numOfPx;	
    	
    	var move = false;
      var timer;
      
      $(upBtn).hover(function() 
      {
        move = "up";
      },
      function() 
      {
        clearInterval(timer);
    		move = false;
    	});
      
      $(downBtn).hover(function() 
      {
        move = "down";
      },
      function() 
      {
        clearInterval(timer);
    		move = false;
    	});
      
      timer = setInterval(animateDiv, interval);
      
      function animateDiv() 
      {
        if (move == "up")
          $(inputDiv).attr('scrollTop',$(inputDiv).attr('scrollTop') - numOfPx);
        else if (move == "down")
          $(inputDiv).attr('scrollTop',$(inputDiv).attr('scrollTop') + numOfPx);
        else
          return null;
      }
    };
  })(jQuery);  
  
  
  
  
 /*** Functions ***/ 




////GetParameters
  function GetParameters(href)
  {
    var arg = new Object();
  
    if ( href.indexOf( "?") != -1)
    {
      var params = href.split( "?")[1];
      var param = params.split("&");
      
      for (var i = 0; i < param.length; ++i)
      {
        var name = param[i].split("=")[0];
        var value = param[i].split("=")[1];
        
        arg[name] = value;
      }
    }
    return arg;
  }  

