 var $j = jQuery.noConflict();
 var active = null;
 var old = null;
 var timeOut = null;
 var nextNum = 0;
 var activeDevice = null;
 var oldDevice = null;
 
 $j(document).ready(function()
  {		
		 			
		$j("#sliderDevice div:visible").hide();
		$j("#sliderDevice .1").show();
		
		if ( $j("#sliderDevice .1 .iphone").length != 0){ $j("#sliderDevice .1 .iphone").show(); activeDevice='iphone'; }
		if (($j("#sliderDevice .1 .iphone").length == 0) && ($j("#slideshow .1 .android").length != 0)){ $j("#sliderDevice .1 .android").show(); activeDevice='android';}		
		if (($j("#sliderDevice .1 .iphone").length == 0) && ($j("#slideshow .1 .ipad").length != 0)){	$j("#sliderDevice .1 .ipod").show(); activeDevice='ipad';}
		if (($j("#sliderDevice .1 .iphone").length == 0) && ($j("#slideshow .1 .ipadl").length != 0)){	$j("#sliderDevice .1 .ipodl").show(); activeDevice='ipadl';}
		if (($j("#sliderDevice .1 .iphone").length == 0) && ($j("#slideshow .1 .blackberry").length != 0)){	$j("#sliderDevice .1 .blackberry").show(); activeDevice='blackberry';}
		if (($j("#sliderDevice .1 .iphone").length == 0) && ($j("#slideshow .1 .iphonel").length != 0)){$j("#sliderDevice .1 .iphonel").show(); activeDevice='iphonel';}
		
		active='1';
		request = 'screen_1'
	  
	  $j("#sliderAppDevices a").click(function(event){
		    event.preventDefault();
			clearTimeout(timeOut);
			
			requestDevice = $j(this).attr('class');
			
			if (activeDevice != requestDevice){
				
				oldDevice = activeDevice;
				activeDevice = requestDevice;
				
				//console.log(activeDevice);
				$j("#sliderDevice ."+active+" ."+oldDevice).fadeOut('fast', function(){$j("#sliderDevice ."+active+" ."+activeDevice).fadeIn('slow');});
				
			}
	  });
	  
	  $j("#sliderApps ul a").click(function(event, simulated){
		    event.preventDefault();
			
			if(!simulated){	clearTimeout(timeOut);}
			
			request = this.id.substr(this.id.length - 1);

			if (active!=request){
				
				old = active;
				active = request;

					
				//move arrow to appropriate position
				$j("#sliderArrow").animate({marginLeft: (active-1)*132 -10});
				//hide blue active link
				$j("#thumb_"+old).removeClass('active');
				//show new thumb as active
				$j("#thumb_"+active).addClass('active');
				//hide old screenshot
					//zmena projektu
					$j("#sliderDevice ."+old).hide();
					$j("#sliderDevice ."+active).show();
					//zmena devicu zacne zakrytim stareho, potom zistime, ci existuje novy
					$j("#sliderDevice ."+old+" ."+activeDevice).hide();
						if ( $j("#sliderDevice ."+active+" ."+activeDevice).length == 0){ activeDevice='iphone'; }
						if ( $j("#sliderDevice ."+active+" ."+activeDevice).length == 0){ activeDevice='ipod'; }
						if ( $j("#sliderDevice ."+active+" ."+activeDevice).length == 0){ activeDevice='ipodl'; }
						if ( $j("#sliderDevice ."+active+" ."+activeDevice).length == 0){ activeDevice='android'; }
						if ( $j("#sliderDevice ."+active+" ."+activeDevice).length == 0){ activeDevice='blackberry'; }
						if ( $j("#sliderDevice ."+active+" ."+activeDevice).length == 0){ activeDevice='iphonel'; }
						$j("#sliderDevice ."+active+" ."+activeDevice).show();
					
				//after finished with showing new app on slider, show new screenshot
				$j("#mainSlider").animate({left:-960*(active-1)}, 'slow', 'easeInOutExpo', function(){});	
		
				
			}		
	  });
	  
	  (function autoAdvance(){
			// Simulating a click on the next arrow.
			if (document.hasFocus ()){
				nextNum += 1;
				if (nextNum > 7){ nextNum = 1;}
				$j('#thumb_'+nextNum).trigger('click',[true]);
				//console.log(nextNum);
			}
			// Schedulling a time out in 2 seconds.
			timeOut = setTimeout(autoAdvance,5000);
		})();
	
  });  

