//
// home2012.js
//
// $Id$
// Copyright (C) 2001 - 2011, Teknolist
//

$(window).load(
	function() {	
		// Footer dock start
		$('.footer_top li').each(function(){
		var iwidth = $(this).find('img').width();
		var iheight = $(this).find('img').height();
		$(this).attr('rel',iwidth+'-'+iheight);
		});
		// Footer dock end
	}
);

$(document).ready(function(){

	//$('#username').focus();
   
	// Footer Resize Start   
   var h_height = $('.header').height();
   
   if($('.header_line_bg').html())
      var h_height = h_height + $('.header_line_bg').height();
   
   if($('.clist').height() > 0)
      var h_height = h_height + $('.clist').height();
   else
      var h_height = h_height + $('#content').height();
      
   var h_height = h_height + $('#footer').height();   
   var w_height = $(window).height();

	if(w_height > h_height)
		$('#footer').removeClass('static');
		
	$(window).resize(function(){
	var w_height = $(window).height();
   var d_height = $(document).height();
		if(w_height > h_height)
			$('#footer').removeClass('static');
		else
			$('#footer').addClass('static');
	});
	// Footer Resize End

   if($('#superbgimage').html())
   {
      $('#superbgimage').superbgimage({
         randomtransition: 0,
         slideshow: 0,
         vertical_center: 0
      }).hide();
   }
		
	// Rotator Start			
	
	var li_length = $('.rotator_content_bg ul li').length;
	var r_width = $('.rotator_content_bg').width();
	var li_total = li_length * r_width;

	$('.rotator_content_bg ul').css({'width' : li_total});

	for(i=1; i <= li_length; i++)
	{
		var clas = ((i==1)? 'current' : '');
		$('.rotator_paging').append('<a id="R'+i+'" class="'+clas+'" href="javascript:;"></a>');
	}
   
   
	var rwidth = $('.rotator_paging').width();
	$('.rotator_paging').css({'width' : rwidth, 'float' : 'none'});

	var elem = $('.rotator_content_bg ul');
	var control = li_total - r_width;
   
	function RotateStart(){
		oynat = setInterval(function(){
			var marginl = $(elem).css("margin-left");
			
			if(parseInt(marginl) + control <= 0)
			{
				$(elem).stop().animate({marginLeft : 0}, 400);
				$('.rotator_paging .current').removeClass('current');
				$('.rotator_paging #R1').addClass('current');						
			}
			else
			{
				$(elem).stop().animate({marginLeft : '-=' + r_width}, 400);
				$('.rotator_paging .current').removeClass('current').next().addClass('current');
			}
		}, 5000); 
	}; 

	RotateStart();
   
   
	$(".rotator_paging a").click(function() {
   
		clearInterval(oynat);      

		var gelen = parseInt($(this).attr("id").replace("R", ""));
		var new_margin = (gelen - 1) * r_width;
		$(elem).stop().animate({marginLeft : '-' + new_margin}, 400);
		$('.rotator_paging .current').removeClass('current');
		$('#R'+gelen).addClass('current');
		
		RotateStart();
      
	});
   
   
   $('.rotator_content_bg').hover(function(){
      clearInterval(oynat);
   }, function()
   {
      RotateStart();
   });
   
   
	// Rotator End
		
	// Hover Menu Start
	$(".logo, #hover_menu").hoverIntent({    
		over: 
		  function(){
			$('#hover_menu').slideDown();
		  },       
		timeout: 100,
		out: function(){
			if(!menu_hover){ $('#hover_menu').slideUp(); }
		}
	});

	var menu_hover = false;

	$('.logo, #hover_menu').hover(function(){ 
		menu_hover = true; 
	}, function() { 
		menu_hover = false; 
	});

	$('body').mouseup(function(){ 
	  if(! menu_hover) $('#hover_menu').slideUp();
	});
	// Hover Menu End

	// Footer dock start
	$('.footer_top li').hover(function(){
      
      var elem = $(this).next().find('img').attr('src');      
      
		var new_src = elem;
		$(this).find('img').attr('src',new_src);
		
		var isize = $(this).next().attr('rel');	
		var iwidth = isize.split("-")[0];
		var iheight = isize.split("-")[1];
		$(this).find('img').animate({width: iwidth, height: iheight, marginTop:'10%'}, 200); 	
	},
	function(){
		var isize = $(this).attr('rel');
		var iwidth = isize.split("-")[0];
		var iheight = isize.split("-")[1];
		$(this).find('img').animate({width: iwidth, height: iheight, marginTop:'16%'}, 200); 
		
		var new_src = $(this).find('img').attr('src').replace("_hover", "");
		$(this).find('img').attr('src',new_src);
	});
	// Footer dock end
	
	// Popup Close Start
	$('.popup_close').click(function(){
		$('#dialog').hide();
		$('#popup_fade').hide();
      $('.popup_display').html('');
      $('.popup_display').css({'padding' : '', 'color' : ''});
      RotateStart();
	});
   
   $('#popup_fade').click(function(){
      if($('#dialog').attr('rel') == 'modal')
      {
         $('#dialog').hide();
         $('#popup_fade').hide();
         $('.popup_display').html('');
         $('.popup_display').css({'padding' : '', 'color' : ''});
         $('#dialog').attr('rel','');
         RotateStart();
      }
      return false;
	});
	// Popup Close End

});
	
// User Tab Start
function user_tab(q){
	var clas = $(q).attr('class');
	if(clas == 'register_button')
	{
		$('.user_right_top').css({'background-position' : 'left -43px'});
		$('.login').hide();
		$('.register').show();
	}
	else
	{
		$('.user_right_top').css({'background-position' : 'left top'});
		$('.register').hide();
		$('.login').show();
	}
}
// User Tab End

// Submit Login
function submit_login () {
   if ($('#username').val() && $('#password').val()) {
      return true;
   }
   return false;
}
// Submit Login End
	
// Popup Function start
function show_frame(u,w,h,t,m,c)
{
   $('.popup_display').html('');
   
   if(typeof(t) != 'undefined')
      $('.popup_close').removeClass().addClass('popup_close').addClass(t)
   else
      $('.popup_close').removeClass().addClass('popup_close');
      
   if(typeof(m) != 'undefined')
   {
      if(m == 1)
      $('#dialog').attr('rel','modal');
   }   
      
	var w_height = $(window).height();		
	var n_height = w_height - h;
	var n_hg = n_height - 20;
	var n_h = n_hg / 2;
	if(w_height < h)
		var n_h = 0;
		
	$('.popup_display').html('<iframe id="'+Math.round(Math.random() * 100000000000)+'" src="'+u+'" width="100%" height="100%" frameborder="0"></iframe>');
	
	$('#dialog').show();
	$('#popup_fade').show();
	$('.dialog_popup').css({'width' : w});
	$('.popup_display').css({'height' : h});
   $('.popup_display').css({'padding' : '', 'color' : ''});
	//var hs = -h / 2;
	$('#dialog').css({'top' : n_h});	
   $('.pop_horizantal').css({'height' : h});
   $('.pop_vertical').css({'height' : h});

   clearInterval(oynat);
}

function hide_frame()
{
   $('#dialog').hide();
   $('#popup_fade').hide();
   $('.popup_display').html('');
   RotateStart();
}

function popup_co(u,w,h,t,m)
{
   $('#dialog', window.parent.document).hide()
   $('#popup_fade', window.parent.document).hide()
   
   parent.show_frame(u,w,h,t,m);
}

function change_frame(w,h)
{
   if(w == 0)
   {
      $('.popup_display').animate({
         height: h
      },800, function(){});

   }else if(h == 0)
   {
      $('.dialog_popup').animate({
         width: w
      },800, function(){});
      
   }
   else
   {
      $('.popup_display').animate({
         height: h
      },800, function(){});
      
      $('.dialog_popup').animate({
         width: w
      },800, function(){});

   }
}

function change_iframe(q)
{
   $('.change_iframe').html('');
   $('.change_iframe').html('<iframe width="100%" height="100%" frameborder="0" src="'+q+'" id="'+Math.round(Math.random() * 100000000000)+'"></iframe>');
}
// Popup function end

function get_content(content) {
 var directory = content.split("/");
 directory = directory[2].split(".");

 $('.ct_right').html('');
 $('.ct_right').html('<embed width="100%" height="100%" name="plugin" src="'+content+'" base="'+directory[0]+'\" type="application/x-shockwave-flash">');
}

// Get parameter
function getParameter(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(window.location.href);
  if(results == null)
    return "";
  else
    return results[1];
}
// Get parameter

(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
