//var order;

var root;
var api;
var scrolling;

$(document).ready(function(){
	//$(document).snowfall({flakeCount:100,round:false,shadow:true});		
});
$(window).load(function() {
$('img#server').attr('src','/img/server.png');
$('.zopim').delay(600).fadeIn(600);

		//$('#wrapper').delay(200).animate({visibility:'visible'},1000);

	//$('#wrapper').animate({opacity:'1.0','filter':'alpha(opacity=1.0)'});
	//$('iframe').contents().find(".by_zopim").hide();	
	$('#wrapper').delay(200).fadeIn(1000);
		
	//$('#wrapper').show(500);

	$('.preview').live("click",function(){

		//$('.preview').colorbox({iframe:false, innerWidth:500, innerHeight:'auto',initialWidth:'200',initialHeight:'80',width:'400',href:this.href, open:true});

		//$.fn.colorbox({href: $(this).attr('href')}); 

		return false;								

	});
	
	
		
	
	
	$('#gtalk-help').live('click',function(){ 
		//$('#gtalk').remove();
		//alert($('#gtalk').size());
		if ( $('#gtalk').size() == 0 ){
			$('#phones').append('<iframe id="gtalk"  src="http://www.google.com/talk/service/badge/Show?tk=z01q6amlqgief9p8h4n7ojqsnmafb10p50mgro87b75h5uhdokfngpasjlbj6r7o26kgv7of9hq5ugn9btkjpu0eu52fb7891sll9ek6v1hb7t1c6t4hkbpfm1h3k56dkjftrvlf6h15n465o27uv6bl0tctpmp53oeb5v55tioqc9rgu88fmms3flotntokfjo5sga4eedagcme15u9ogtbi68b0&amp;w=200&amp;h=60" frameborder="0" allowtransparency="true" width="200" height="60"></iframe>');
			$('#gtalk').fadeIn(600);
			return false;
		}

		$('#gtalk').ready(function(){
			if ( $('#gtalk').is(':hidden')){
				$('#gtalk').fadeIn(600);	
			} else {
				$('#gtalk').fadeOut(600);
			}
		});
	});

	$('#enter').live("click",function(){
								//$('iframe .by_zopim').remove();
								//alert($('#gtalk').contents().find('.a').attr('href'));
								
								//alert($('#gtalk .a').attr('href'));
							   $(".login").show("explode",null,"medium");



							  //$('.login').slideDown();

							  

							   return false;});

	

	$('.login-close').live('click',function(){ 

								//$(".login").hide("explode");	 

								$(this).parent().hide("explode");

							   //$('.login').slideUp();

							 	return false;});

	$('.ajax-link').live('click',function(){
		var url = $(this).attr('href');
		$('#ajax-loader').fadeIn();
		$('#wrapper').fadeOut(1000);
		
		//$('#wrapper,#content,#footer').fadeOut(500);
		//$('#content').animate({visibility:'hidden'});
		$('#content').load('http://pro-it.bg'+url,function(){ 
				//$('#content,#footer,#wrapper').delay(10).fadeIn(); 
				$('#ajax-loader').delay(100).fadeOut();
				$('#wrapper').fadeIn(1000);
				
				
		});
		//$('#content').html(data).show("blind");
		
	});

	$('#jmenu ab').live('click',function(){

			

			var url = $(this).attr('href');

			if (url == undefined) {

				return false;	

			}


			/*
			$('#footer').hide();

			$('#content').hide('blind',500);
			*/
			$('#logo').hide();
			$('#ajax-loader').fadeIn();
			$('#content,#footer,#header').fadeOut(700);
			//$('#header').delay(300).show();
			//alert('http://pro-it.bg'+url+' #content');

			//$('#content').load('http://pro-it.bg'+url,function(){ $('#content').show("blind"); });

			//$('#content').load(url,function(){ $('#content').delay(2000).show("blind"); });

			$.get(url, function(data) {

			  //$('#content').html(data).show("blind");
				$('#content').html(data);
				$('#ajax-loader').delay(100).fadeOut();
				$('#header').fadeIn(500);
				$('#content').fadeIn(500);
				$('#footer').fadeIn(500);
				$('#logo').delay(800).fadeIn(500);
				if ($('.scrollable')){
						root = $(".scrollable").scrollable({circular:true, mousewheel: false}).navigator().autoscroll({ autoplay: true,interval: 10000 });
						api = root.data("scrollable");
						

				}
				
				//if ($("#tabs")){
					//$("#tabs").tabs();
				//}
			
			});



			//$('#footer').show('blind');

			//alert($(this).attr('href'));

			if ($(this).attr('href') == "/pages/control") {
				//$("#tabs").tabs();
				
			}

			if ($(this).attr('href') == "/pages/video") {

				

				if ( $('#camera').is(':hidden')){

					$(".front-image").hide();
					$("#camera").delay(10).show();

				}

				

			} else if ($(this).attr('href') == "/pages/control") {

				if ( $('#control').is(':hidden')){

					$(".front-image").hide();

					$("#control").delay(10).show();

				}

			} else {

				if ( $('#server').is(':hidden')){

					$(".front-image").hide();

					$("#server").delay(10).show();

				}

			}

			

			

			

			/*

			if ($(this).attr('href') == "/pages/video") {

				

				//$('img.front-image').attr('src','/img/camera.png');

				

				$(".front-image").css("z-index",2);

	//			ele = $("img.front-image").clone().css({position:"relative","top":"-"+$(".front-image").eq(0).height()+"px","z-index":"1"}).attr("src","/img/camera.png");

		//ele = $(".front-image").clone().css({position:"absolute","top":"-"+$(".front-image").eq(0).height()+"px","z-index":"1"}).attr("src","/img/camera.png");

		ele = $(".front-image").clone().fadeIn(1500).attr("src","/img/camera.png");

//				$(".front-image").after(ele).fadeOut();

				$(".front-image").after(ele).fadeOut().remove();

				//$(".front-image").animate({top:0},1000);

			} else if ($(this).attr('href') == "/pages/control") {

				if ($('.front-image').attr('src') != '/img/control.png') {

					$(".front-image").css("z-index",2);

	//			ele = $("img.front-image").clone().css({position:"relative","top":"-"+$(".front-image").eq(0).height()+"px","z-index":"1"}).attr("src","/img/camera.png");

		//ele = $(".front-image").clone().css({position:"absolute","top":"-"+$(".front-image").eq(0).height()+"px","z-index":"1"}).attr("src","/img/control.png");

		ele = $(".front-image").clone().fadeIn(1500).attr("src","/img/control.png");

//				$(".front-image").after(ele).fadeOut();

				$(".front-image").after(ele).fadeOut().remove();

				//$(".front-image").animate({top:0},1000);

				}

			} else {

				if ($('.front-image').attr('src') != '/img/server.png') {

				$(".front-image").css("z-index",2);

		//ele = $(".front-image").clone().css({position:"absolute","top":"-"+$(".front-image").eq(0).height()+"px","z-index":"1"}).attr("src","/img/server.png");

		ele = $(".front-image").clone().fadeIn(1500).attr("src","/img/server.png");		

				$(".front-image").after(ele).fadeOut().remove();

				//$(".front-image").animate({top:0},1000);

				}

				

			}

			*/

			return false;

	});

	

	

	$('.read-more').live('click',function(){

		$('.faq-text').hide().css({padding:'0px'});

		$('.right-faq-main-title a').css({color:'#1A4D9D'});

		$('.right-faq').css({border:'0px solid red'});

			

		

			

			//$(this).parent().children('.faq-text').css({padding:'20px'}).show("explode").delay(1000).css({color:'#333'});
			//$(this).parent().children('.faq-text').slideDown("medium").delay(1000).css({color:'#333'});
			$(this).parent().children('.faq-text').show("blind").css({color:'#333',paddingLeft:'60px'});
			
			$(this).parent().find('.right-faq-main-title a').css({color:'red'});

			$(this).parents(".right-faq").css({'border-bottom':'1px solid blue'}).delay(100).animate({borderBottomColor:'red'});

//			$(this).parents(".right-faq").animate({borderBottomColor:'red'});

//			$(this).parent().css({color:'#ccc'});

		

		//$('.faq-text').slideUp();

		//$('.faq-text').fadeOut();

		

		

		

		return false;

	

	});

	

	

	/*$('.service').live({

        mouseenter:

           function()

           {

			   alert(this);

				$(this).animate({'backgroundPosition':'0 -199px'});	

           },

        mouseleave:

           function()

           {

				$(this).animate({'backgroundPosition':'0 0'});	

           }

       }

    );*/



	$(".service")

    .live('mouseenter',function() {

        $(this).css({'backgroundPosition':'0 -199px'});	

    })

    .live('mouseleave',function() {

       	$(this).css({'backgroundPosition':'0 0'});

    });



	

	var run = 0;

	

	$('.service-icon-holder a,.service h3').live('click',function(){

		

		var cid = $(this).parents('.service').attr('rel');

		$('.service').children('h3').css({color:'#6D6D6D'});

		

		if (run == 0){

			run = 1;

			$('.text-holder').fadeOut();

			$(this).delay(500).parents('.service').children('h3').animate({color:'#002f67'},1800);

			

			//$('.text').css({visibility:'hidden'});

			

			//$('#text-'+cid).delay(800).css({visibility:'visible'});

			$('#text-'+cid).delay(800).show('blind',1000).fadeIn(500,function(){ run = 0;});

			

		}
			return false;
	});

	
	$(window).scroll(function () { 
      //$(".star").fadeOut().delay(2000).fadeIn(); 
	  //$(".star").hide().delay(2000).show();
    });


	//var ifr = $('iframe').contents().find('.by_zopim');
	//$(ifr).live('click',function(){ alert('Zopim test');return false;});
	$('#map-link').live('click',function(){
				$('#map-holder').toggle('blind');
	});
	$('#map-holder').live('click',function(){
				$('#map-holder').hide('blind');
	});
	
	//setInterval(function(){ $('.tabs li:visible').fadeOut().nextAll().fadeIn(); },2000);
	
	root = $(".scrollable").scrollable({circular:true, mousewheel: false}).navigator().autoscroll({ autoplay: true,interval: 10000 });
	api = root.data("scrollable");
	
	
	$(".scrollable").live('mouseenter',function() {
		clearInterval(scrolling);
        api.pause();
    }).live('mouseleave',function() {
       	scrolling = setTimeout(function(){api.play();},10000);
    });

});


