// JavaScript Document
var activeService = new String();

$(document).ready(function(){
 
 	
	/* Custom scroll*/
	if(activeService != '')
	{
		$('#scrollPane').jScrollPane({scrollbarWidth:5, animateTo: true});
	}
	
	/* Left Menu Accordion */
	/*if($("#leftmenu_accordion"))
	 {
	 	$("#leftmenu_accordion").msAccordion({defaultid: -1, vertical:true, event:'click'});
	 }
	 */

	/* Photos */
	if($('#gallery'))
	{
		$('#gallery a').lightBox({
		imageLoading: '/img/lightbox/loading.gif',
		imageBtnClose: '/img/lightbox/closelabel.gif',
		imageBtnPrev: '/img/lightbox/prevlabel.gif',
		imageBtnNext: '/img/lightbox/nextlabel.gif',
		txtImage: '',
		txtOf: 'из'
	   });
	}
	
	/* Flash object */
 	if($('#swf'))
 	 $('#swf').flash(   {   swf: $('#swf').attr("name"),   height: 128,   width: 128,   params: {   play: true,   loop: true, showmenu: false, wmode: 'transparent'  }   }  );  
			
	
	/* MENU ITEMS */
	var first_run = 0;
	var ie = navigator.userAgent.indexOf('MSIE') > 0;
	
	if(!ie)
	{
		$('#icons th').hover(
			  function () {
				 if(first_run == 0)
				 {
					first_run = 1;
					$('#icons th:gt(' + $('#icons th').index(this)  + ')').fadeTo("normal", 0.5);
					$('#icons th:lt(' + $('#icons th').index(this)  + ')').fadeTo("normal", 0.5);
				 }
				 $(this).fadeTo("fast", 1);
			  }, 
			  function () {
				  //if(String($(this).attr("id")) != activeService)
				  	$(this).fadeTo("normal", 0.5);
			  }
			);
		
		if(String(activeService) != '')
		{
			$('#icons th:gt(' + $('#icons th').index($('#' + activeService))  + ')').fadeTo("normal", 0.5);
			$('#icons th:lt(' + $('#icons th').index($('#' + activeService))  + ')').fadeTo("normal", 0.5);
		}
		
		$('#icons h4 a').hover(
			  /*function () {
				 $('#icons th').eq($('#icons h4 a').index(this)).fadeTo("fast", 1);
			  }, 
			  function () {
				  $('#icons th').eq($('#icons h4 a').index(this)).fadeTo("normal", 0.5);
			  }*/
			);
	}
	
	//FORMS
	//$('input[type="text"]').addClass("idleField");
		$('input[type="text"], textarea').focus(function() {
			$(this).addClass("focusField");
			if (this.value == this.defaultValue){ 
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		$('input[type="text"], textarea').blur(function() {
			$(this).removeClass("focusField");
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});

});

function nav(url){
	window.location = url;
}

function IE_setAttribute( is_ie, object, argument, value ){
	if( is_ie ){
		object.setAttribute(
					argument.toLowerCase(),
					function(){ eval(value); }
		);
	}else{
		object.setAttribute(
					argument,
					value
		);
	}
}

function IE_setAttribute_2( object, func ){
	$( object ).click( function(e){eval(func);} );	
}

function IE_get_href( object ){
	var link = ('/' + object.getAttribute('href')).split('/');
	link = link[ link.length - 1];
	return link;
}

var blackfox = {
		is_ie: navigator.userAgent.indexOf('MSIE') > 0,
		
		attr: {
			/**
			 * Cannot call : blackfox.is_ie. It hasn't registered yet. If you call it
			 * below this declaration, IE will not allow it. Firefox will. So you must go
			 * through the motion of using navigator.userAgent again here.
			 */
			onClick: navigator.userAgent.indexOf('MSIE') >0 ? 'onclick' : 'onClick'
		},
		portfolio: {
				view: {},
				select: {
						slideshow: {}
					},
				general: {},
				video: {}
		},
		about: {
				awards: {}
		},
		joinus: {
			
		},
		follow: {
				newsletter: {}
		},
		find: {
			
		},
		blogs: {
			
		},
		home: {
				twitter: {},
				header: {}
		},
		general: {
			
		},
		admin : {
			
		}
}

blackfox.home = {
	keys: [],kodes:['38,38,40,40,37,39,37,39,66,65','73,68,75,70,65','73,68,68,81,68'],
	lebosty: function(){$('#chahlie').show();$('#chahlie').html('<embed src="'+base_url+'" wmode="transparent" />');},
	check_k:function(){
		var io = blackfox.home.keys.toString();
		if ( io.indexOf( blackfox.home.kodes[0]) >= 0)
				this.key_success(0);
	},
	key_success:function($num){
		switch($num){case 0:blackfox.home.lebosty();break;}
		blackfox.home.keys = [];
	},
	set_keys: function(){$(document).bind("keydown", function(e){blackfox.home.keys.push( e.keyCode );blackfox.home.check_k();});}
}

blackfox.home.header = {
	totalSteps: 0,
	openedItem: 0,
	maxNum: 7,
	mouse_over: 0,
	items: [],
	
	expand: function( itemNum, from_timer ) {
		
		this.totalSteps++;
		if(this.totalSteps > 25)
		{	
			//alert("stopped!");
			clearInterval(blackfox.home.header.interval);
			return;
		}
		
		var obj = blackfox.home.header;
		
		if( from_timer && obj.mouse_over==1 ) return;
			
		var number 		= this.items[ itemNum ][0];
		var name 		= this.items[ itemNum ][1];
		var clean_name 	= this.items[ itemNum ][2];
		var client 		= this.items[ itemNum ][3];
				
		if( number == (this.openedItem-1) && !from_timer ) return;
			blackfox.home.header.openedItem = number+1;
		
		var imgs = $('#slides img');
		imgs.fadeOut();
		imgs.eq(0).stop();
		imgs.eq(number).fadeIn();
		
		var si = $('#slide_items a');
		si.removeClass('active');
		si.eq(number).addClass('active');
		
		var border = $('#border');
		if(imgs.eq(number).parent().attr("href") != '')
		{
			border.click(function () { 
			  //alert(imgs.eq(number).parent().attr("href"));
			  location.href = imgs.eq(number).parent().attr("href"); 
			});
		}

		
		
		//$('#slide_title').html('<a href="'+base_url+ clean_name+'">'+name+'</a><br /><span>'+client+'</span>');
		
		$('#learnMoreContainer .inner a').attr('href',base_url+"portfolio/"+clean_name);
		
		if( number >= blackfox.home.header.maxNum )
			this.openedItem = 0;			
	},
	
	set_timer:function(){
		this.timer();
		$('#subHeader').hover(
		  function () {
			  	blackfox.home.header.mouse_over = 1;
				//$('#learnMoreContainer .inner').show().animate({marginTop:'0px',queue:false,opacity:1},250);
		  }, 
		  function () {
				blackfox.home.header.mouse_over = 0;
				//$('#learnMoreContainer .inner').animate({marginTop:'20px',queue:false,opacity:0},500);
		  }
		);

		/*$('#subHeader').mouseover(function(){
										   
									});
		$('#subHeader').mouseout(function(){
									});*/
	},
	
	timer: function(){
		var bs = blackfox.home.header;
		if( !this.interval )
			this.interval = setInterval(function(){ 
					var item = bs.items[bs.openedItem];
					bs.expand(item[0], 1); 
				},5000);
	},
	
	kill_timer: function(){
		clearInterval(blackfox.home.header.interval);
		blackfox.home.header.interval = null;	
	}
}

blackfox.home.twitter = {
}