jQuery(document).ready(function(){

/*
 * 
 * START dropdown menu
 * 
 */	
	jq(".has_dropdown").hover(function() {		
		e = this;
		jq(e).children(".me_dropdown").stop(true, true).fadeIn('fast');
	}, function() {
		jq(e).children(".me_dropdown").stop(true, true).fadeOut('fast');
	});
/*
 * 
 * END dropdown menu
 * 
 */


/*
 * 
 * START tooltips from title
 * 
 */
	jQuery("span, a, .fb_send_button").tipsy({
		gravity:	's',
		fade:		true,
		delayIn: 	500
	});
	
	jQuery(".fb_send_button").tipsy({
		gravity:	'se',
		fade:		true
	});
/*
 * 
 * END tooltips from title
 * 
 */



/*
 * 
 * START change font size
 * 
 */
	jQuery('.change_font_size').click(function(){
		
		var ourText = jQuery('#con');
		var currFontSize = ourText.css('fontSize');
		var finalNum = parseFloat(currFontSize, 10);
		var stringEnding = currFontSize.slice(-2);
		if(this.id == 'font_plus') {
			finalNum *= 1.2;
		}
		else if (this.id == 'font_minus'){
			finalNum /=1.2;
		}
		ourText.stop().animate({fontSize: finalNum + stringEnding},600);
		
	});



/*
 * 
 * END change font size
 * 
 */

	

	
	
	
/*
 * 
 * START sticky banner
 * 
 */
	function stickyBanner(topOffset, leftOffset){
	    jQuery(window).scroll(function(){
	            if( jQuery(window).scrollTop() > topOffset) {
	                    jQuery('#sidebar-right .banner').css({position: 'fixed', top: '5px', 'z-index': 99});
	            } else {
	                    jQuery('#sidebar-right .banner').css({position: 'static'});
	            }
	    });
    }
    
	// make the menu sticky so that it's always in view
    var stickyBannerTop = jQuery('#sidebar-right .banner').offset().top; // Check the initial Poistion of the Sticky Header (http://www.ruturaj.net/auto-sticking-header-with-scroll-jquery)
    var stickyBannerLeft = jQuery('#sidebar-right .banner').offset().left; 
    stickyBanner(stickyBannerTop, stickyBannerLeft);
    
    
    jQuery(window).resize(function() {
		newStickyBannerTop = jQuery('#sidebar-right .banner').offset().top;
    	newStickyBannerLeft = jQuery('#sidebar-right .banner').offset().left;
    	stickyBanner(newStickyBannerTop, newStickyBannerLeft);
	});
/*
 * 
 * END sticky banner
 * 
 */




/*
 * 
 * START overlay captions for images (in articles)
 * 
 */
	jQuery("#main .box_info_content .katava div img, #main .box_info_content .katava p img").each(function(index) {
		e = this;
		if ( (jQuery(e).attr('title')) && (jQuery(e).attr('title') != '') ){
			jQuery(e).removeAttr('title').captify({
				animation: 'always-on'
			});
		}
	});
	
	// fix for centering images which have had captions applied
	jQuery(".caption-wrapper").css("margin-right", "55px");
/*
 * 
 * END overlay captions for images (in articles)
 * 
 */



/*
 * 
 * START smooth scroll anchors
 * 
 */
	jQuery('#main .box_info_content a').bind('click', function(event) {
		e = this;
		elementClick = jQuery(e).attr("href")
        if (elementClick.substring(0,1) == "#"){
        	destName = elementClick.split("#")[1];
           	destination = jQuery('a[name="'+destName+'"]').offset().top;
        	jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-10}, 1100 );
           	event.preventDefault();
        }
	});
/*
 * 
 * END smooth scroll anchors
 * 
 */



/*
 * 
 * START the featured slider on hompages (thanks to: http://webdeveloperplus.com/jquery/featured-content-slider-using-jquery-ui/)
 * 
 */	
	jQuery('#featured').tabs({event: 'mouseover'}).tabs('rotate', 4000, true).hide().css('visibility','visible').fadeIn('slow');
	
	// use the list item's rel attribute to redirect the browser to the relevant webpage - this is because the list item's a href is used to configure the slider
	jQuery('#featured ul li a').bind('click', function(event) {
		e = this;
		goTo = jQuery(e).attr("rel");
		window.location = goTo;
		event.preventDefault();
	});
	
	// when hovering over one of the items then stop auto-rotating (and when leaving continue rotating)
	jQuery("#featured").hover(  
		function() {  
			jQuery("#featured").tabs("rotate",0,true);  
		},  
		function() {  
			jQuery("#featured").tabs("rotate",4000,true);		
		}
	);
/*
 * 
 * END the featured slider on hompages http://webdeveloperplus.com/jquery/featured-content-slider-using-jquery-ui/
 * 
 */




/*
 * 
 * START special services iframe modal
 * 
 */
	/*
	jQuery("#special_services_hotels_url").colorbox({
		fastIframe:		false,
		escKey:			false,
		overlayClose: 	false,
		iframe:			true,
		opacity:		0.5,
		width:			"90%",
		height:			"80%"
	});
	*/
/*
 * 
 * END special services
 * 
 */



/*
 * 
 * START related articles slideout box (thanks to: http://tympanus.net/codrops/2010/04/13/end-of-page-slide-out-box/)
 * 
 */
	/*
	if (jQuery('#con #links').length ) { // only do this on the article page
		
		var slidebox 	= jQuery('#slidebox');
		var actionButton	= jQuery('#slidebox_action_button');
		
		var originalHeight 	= slidebox.height();
		var minimizedHeight = 30 - originalHeight;
		var maximizedHeight	= originalHeight - 30;
		
		jQuery(window).scroll(function(){
			
			// when reaching the element with id "last" we want to show the slidebox. Let's get the distance from the top to the element //
			var distanceTop = jQuery('#con #links').offset().top - jQuery(window).height();
			
			if  (jQuery(window).scrollTop() > distanceTop - 50){
				slidebox.animate({'right':'0px'},500);
			} else {
				slidebox.stop(true).animate({'right':'-430px'},300);
			}
			
		});
			
		// minimize the slidebox when clicking the cross //
		jQuery('#slidebox .close').bind('click',function(){			
			
			slidebox.stop(true).animate({'bottom': minimizedHeight},300);
			actionButton.removeClass('close').addClass('open');
			
		});
		
		// minimize the slidebox when clicking the cross //
		jQuery('#slidebox .open').bind('click',function(){
			
			slideboxNew.stop(true).animate({'bottom': '0'},300);
			actionButton.removeClass('open').addClass('close');
		});
	}*/
/*
 * 
 * END related articles slideout box
 * 
 */


/*
 * 
 * START action winter horef sticky footer
 * 
 *
	
	function randomXToY(minVal,maxVal,floatVal)
	{
	  var randVal = minVal+(Math.random()*(maxVal-minVal));
	  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
	}
	
	var wrapper = jQuery('#sticky-footer-wrapper');
	var logo 	= jQuery('#sticky-footer-medraft-logo');
	
	
		
	if (jq.cookie('actionWinterFooterHide') != 1){
		
		
		
		var url1 = '<a target="_blank" href="http://mail2.lametayel.co.il/phplists/goto.php?label=24012012&place=medraft_7%2F3_romania&url=http%3A%2F%2Fwww.lametayel.co.il%2Flanding%2Faction_winter_father_son.html">7/3 סופ"ש ברומניה - אקשן חורף לאבות ובנים. מבצע לגולשי למטייל. היכנסו...</a>';
		var url2 = '<a target="_blank" href="http://mail2.lametayel.co.il/phplists/goto.php?label=24012012&place=%2B%2Bmedraft_with_200_euro&url=http%3A%2F%2Fwww.lametayel.co.il%2Flanding%2Faction_winter_father_son.html">€200 הנחה - אקשן חורף לאבות ובנים. מבצע לגולשי למטייל. היכנסו...</a>';
		
		
		// check if a number cookie exists
		if (jq.cookie('actionWinterFooterNum')){
			
			// get the cookie's number
			urlNum = jq.cookie('actionWinterFooterNum');
			
			if (urlNum == 1){
				jQuery("#sticky-footer p").html(url2);
				urlShown = 2;
			} else {
				jQuery("#sticky-footer p").html(url1);
				urlShown = 1;
			}

			// update the cookie
			jq.cookie('actionWinterFooterNum', urlShown, { expires: 365, path: '/', domain: 'lametayel.co.il' });
			
			// update the table in the database
			
		} else {// else
		
			// if not randomly choose either 1 or 2
			urlShown = randomXToY(1,2);
			
			// update the url to the chosen number
			if (urlShown == 1){
				jQuery("#sticky-footer p").html(url1);
			} else {
				jQuery("#sticky-footer p").html(url2);
			}
			
			// update the cookie to the chosen number
			jq.cookie('actionWinterFooterNum', urlShown, { expires: 365, path: '/', domain: 'lametayel.co.il' });
			
			
			
		}
		
		// update the table in the database
		if (urlShown ==1){
			which = "sofash";
		} else {
			which = "hanacha";
		}
		
		jQuery.post('http://www.lametayel.co.il/ajax-pirsum.php', {aw: 1, which: which});
		
		logo.fadeIn(function(){
			wrapper.delay(1000).animate({bottom: 0}, 1500, function(){
				logo.animate({"margin-top": "-91px"}, 900);
			});
		});
		
		
		
		jQuery("#sticky-footer-medraft-close").bind('click', function(event) {
		  	logo.animate({"margin-top": 0}, 900, function(){
		  		wrapper.animate({bottom: "-90px"}, 1500);
		  	});
		  	
		  	// create a cookie which is used not to show the banner for 24 hours
		  	jq.cookie('actionWinterFooterHide', '1', { expires: 1, path: '/', domain: 'lametayel.co.il' });
		  	
		});
		
	} else {
		wrapper.remove();
	}
	
*/
	

	
		
/*
 * 
 * END action winter horef sticky footer
 * 
 */


	
/*
 * 
 * START sticky menu
 * 
 */
	/*function stickyBreadcrumbs(topOffset, leftOffset){
	    jQuery(window).scroll(function(){
	            if( jQuery(window).scrollTop() > topOffset) {
	                    jQuery('#bar #bottom_bar').css({"width": "987px", position: 'fixed', top: '0px', left: leftOffset, 'z-index': 9999, '-webkit-box-shadow': '0px 1px 3px 1px #7F7F7F', '-moz-box-shadow': '0px 1px 3px 1px #7F7F7F', 'box-shadow': '0px 1px 3px 1px #7F7F7F'});
	            } else {
	                    jQuery('#bar #bottom_bar').css({position: 'static', top: '0px', 'z-index': 9999, '-webkit-box-shadow': 'none', '-moz-box-shadow': 'none', 'box-shadow': 'none'});
	            }
	    });
    }
    
	// make the menu sticky so that it's always in view
    var stickyHeaderTop = jQuery('#bar #bottom_bar').offset().top; // Check the initial Poistion of the Sticky Header (http://www.ruturaj.net/auto-sticking-header-with-scroll-jquery)
    var stickyHeaderLeft = jQuery('#bar #bottom_bar').offset().left; 
    stickyBreadcrumbs(stickyHeaderTop, stickyHeaderLeft);
    
    
    jQuery(window).resize(function() {
		newStickyHeaderTop = jQuery('#bar #bottom_bar').offset().top;
    	newStickyHeaderLeft = jQuery('#bar #bottom_bar').offset().left;
    	stickyBreadcrumbs(newStickyHeaderTop, newStickyHeaderLeft);
	});*/
/*
 * 
 * END sticky menu
 * 
 */


/*
 * 
 * START sheleg sticky footer
 * 
 */
	
	/*var stickyFooter = jQuery('#sticky-footer');
	var footerVisible = 140;
	var howManyFlakes = 15;
	shelegPromoUrl = jQuery(".sheleg-countdown-text").html();
	
	if (jq.cookie('shelegCountdownHide') == 1){
		jQuery(".liner #countdown, .liner .liner .sheleg-countdown-text").remove();
		jQuery(".liner .sheleg-countdown-title").html(shelegPromoUrl);
		jQuery(".liner .sheleg-countdown-title a").css({"color": "#54cdf9", "text-decoration": "underline", "font-weight": "bold", "letter-spacing": "1px"});
		jQuery(".liner").css("height", "40px");
		
		footerVisible = 40;
		howManyFlakes = 5;
	}
		
	
	stickyFooter.stickyfooter({
		visible: footerVisible
	});
	
	// snowfall
	jQuery('.liner').snowfall({
			flakeCount : howManyFlakes,        // number
		    flakeColor : '#ffffff', // string
		    flakeIndex: 999999,     // number
		    minSize : 3,            // number
		    maxSize : 5,            // number
		    minSpeed : 0.5,           // number
		    maxSpeed : 1.5,           // number
		    round : true,          // bool
		    shadow : true         // bool
		});
	
	// countdown
	jQuery('#countdown').countdown({
		until: new Date(2012, 1-1, 29, 10, 0, 0), // (year, month (minus 1 - because this is an index), day, hours, minutes, seconds)
		timezone: +2
	});
	
	jQuery("#close_sheleg_countdown").bind('click', function(event) {
		
		stickyFooter.animate({bottom: "-200"}, 1500, function(){
			
			stickyFooter.remove();
		});
		
		jq.cookie('shelegCountdownHide', '1', { expires: 1, path: '/', domain: 'lametayel.co.il' });
		
		event.preventDefault();
	});*/
		
/*
 * 
 * END sheleg sticky footer
 * 
 */





});

