﻿// JavaScript Document
$(document).ready(function()
{

	$("a[rel='lightbox[set1]']").colorbox();
	$("a[rel='lightbox22']").colorbox();
	$("a[rel='lightbox[set2]']").colorbox();
	$(".popap").colorbox({width:"30%", inline:true, href:"#inline_example1"});
	$(".popap2").colorbox({width:"30%", inline:true, href:"#inline_example2"});
	$(".popap3").colorbox({width:"520px", inline:true, href:"#buyit"});
	$(function() {
	   $('.title-a-hover').hover(function() {
		   $(this).parent().find('.theme-day-title').stop().fadeTo('1500',1);
	   }, function() {
	   $(this).parent().find('.theme-day-title').stop().delay(3000).fadeTo('1500',0);
	   });
	});

	var w = 0;
	$(".top-menu li.level1").each(function(){
		w += $(this).width();
	});
	$(".top-menu li.menu-more").css({'marginLeft': w + 'px'});

// $('.border').wrapInner('<div class="border-wrap"></div>').append('<div class="clear"></div>')
	$('.poster .image:not(.noshadow)').each(function(){
		$(this).append('<div class="poster-wet-floor"></div>').find('.poster-wet-floor').each(function(){
			var img = $(this).parent().find('img')			
			$(this).parent()
							.css( "position", "relative" )
							.width( img.width() )
							.height( img.height() )
			var step = 10							
			for ( intStep = 0 ;	intStep <= step ;	intStep++ ){			 
				div = $( '<div class="poster-wet-floor-wrap"></div>' );
				zoom = ((300+(step-intStep))/300)
				div
					.css ({
								opacity: (intStep / 40),
								bottom: ((-step + (intStep) ) + "px"),
								width: img.width()*zoom,
								left: (img.width()-(img.width()*zoom))/2,
								height: '1px',
								overflow: 'hidden',
								position: 'absolute'
							})
				$(this)
						.append(div)
						.find('div:last-child')
				img.clone()
					.css({
						top: ((-step + (intStep) ) + "px"),
						width: img.width()*zoom
					})
					.appendTo($(this).find('div:last-child'));
			}
			});
	})

	$(".left-block .day-theme-tab").tabs({ fx: { opacity: 'toggle' } }).tabs("rotate", 50000, true);;
	$('.new-tab, .new-tab2').tabs({ fx: { opacity: 'toggle' } }).tabs("rotate", 10000, true);;

	if ($(".left-block .tab").length) {
		$(".left-block .tab").tabs();
    }

    // var RandomTab = Math.floor(Math.random() * $(".day-theme-tab li").length);
    $('.day-theme-tab').tabs();
   

	 $('.calendar a').bind('click', function(){
		$('.calendar').find('a').removeClass('active')
		$(this).addClass('active')
		 $('.calendar #calendar_day').val($(this).text())
		return false;
	})

$('.calendar-block .calendar-title').click(function(){
	$('.calendar-block').addClass('active')
})
$('.calendar-block .calendar .calendar-close').click(function(){
	$('.calendar-block').removeClass('active')
})

 $('.bottom-bar input').focus(function(){
	$(this).select()
	 })
	 .click(function(){
		return false;		
	})
	$(".bottom-bar input").bind('focus',function( clickEvent ){
		$(this).select()
			return false			
			//clickEvent.preventDefault();			
		})
	
	
 var search_field = $(".taskbar-search input");
  search_field.blur(function(){
    if(!search_field.val()){ search_field.val("Что ищем?"); search_field.addClass("placeholder"); }
  }).focus(function(){
    if(search_field.val() == "Что ищем?"){ search_field.val(""); search_field.removeClass("placeholder"); }
  })
  $(".taskbar-search form").submit(function() {
    if(search_field.val() == "" || search_field.val() == "Что ищем?") return false;
  })

	$('.show-checkboxes span').click(function() {
		if ( $(this).hasClass('sss') ) {
			$(this).removeClass('sss');
			$(this).closest('form').find('.checkbox-list').slideUp();
		} else {
			$(this).addClass('sss');
			$(this).closest('form').find('.checkbox-list').slideDown();
		}
	});

	$('.show-checkboxes2 span').click(function() {
		if ( $(this).hasClass('sss') ) {
			$(this).removeClass('sss');
			$(this).closest('form').find('.checkbox-list2').slideUp();
		} else {
			$(this).addClass('sss');
			$(this).closest('form').find('.checkbox-list2').slideDown();
		}
	});
	



	function hh(){ 
		if (ie) {
			$(".poster-new-description").hide();
		} else {
			$(".poster-new-description").fadeOut();
		}
	}
	
	var timer;
	var lastdesc;
	if ($.browser.msie && $.browser.version <= '8.0') {	ie = 1 } else { ie = 0}

	$('.poster-new').live("mouseover mouseout", function(event) {
		if ( event.type == "mouseover" ) {
			var x = $(this).position().left;
			var y = $(this).position().top;
			var desc = $(this).attr('id');
			//			alert(lastdesc+" "+desc);
			if (lastdesc != desc) 
			{
				if (ie) {
					$(".poster-new-description").hide();
				} else {
					$(".poster-new-description").fadeOut();
				}
				lastdesc=desc;

			}
			
			clearTimeout(timer);
			
			if (ie) {
			$("#"+desc+"-det").css({'left':x-115+'px', 'top': y+80+'px'}).stop().show();
			} else {
				$("#"+desc+"-det").css({'left':x-115+'px', 'top': y+80+'px'}).stop().fadeIn();
			}
	
		} else {
	
			timer = setTimeout(hh,1000);
			
		}
	});

	$(".poster-new-description").hover(function() {
			clearTimeout(timer);
		}, function() {
			timer = setTimeout(hh,2000);
			
	});


												 
	$('ul#lava-block').lavaLamp();
	
	$('.ico-igive a').click(function() {
		var soc = $(this).parent().find('.soc-icons');
		if ( soc.css('display') == 'none' ) {
			soc.fadeIn();
		} else {
			soc.fadeOut();
		}
		return false
	});


})

