/*---------------------------------------------------------------------

Template Name: 	Online Booking
Version:	 	1.0
Release Date: 	August 08, 2010

File:       	custom.js
Updated:    	2010-08-08

Copyright (c) 2010 Zoran Juric - http://themeforest.net/user/zoranjuric

-----------------------------------------------------------------------

WARNING! DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!

---------------------------------------------------------------------*/

// Site object setup
var Site = {};

// scrollToTop() - scroll window to the top
Site.scrollToTop = function (e) {
    $(e).hide().removeAttr("href");
    if ($(window).scrollTop() != "0") {
        $(e).fadeIn("slow")
    }
    var scrollDiv = $(e);
    $(window).scroll(function () {
        if ($(window).scrollTop() == "0") {
            $(scrollDiv).fadeOut("slow")
        } else {
            $(scrollDiv).fadeIn("slow")
        }
    });
    $(e).click(function () {
        $("html, body").animate({
            scrollTop: 0
        }, "slow")
    })
}

// scroll_to_hash() - scroll window to the tag with #hash id 
Site.scroll_to_hash = function(hash) {
	var ot = $(hash).offset();
	jQuery("html, body").animate({ 
		scrollTop: ot.top 
	}, "slow");
}

// setup() - Site init and setup
Site.setup = function () {
    // Open an external link in a new window
    $('a[href^="http://"]').filter(function () {
        return this.hostname && this.hostname !== location.hostname;
    }).attr('target', '_blank');

    // scroll to top on request
    if ($("a#totop").length) Site.scrollToTop("a#totop");
	
	// setup content boxes (Search Filters)
	if ($(".content-box").length) {
		$(".content-box .header").css({
			"cursor": "s-resize"
		});
		// Give the header in content-box a different cursor	
		$(".content-box .header").click(
		function () {
			$(this).parent().find('.section').toggle(); // Toggle the content
			$(this).parent().toggleClass("content-box-closed"); // Toggle the class "content-box-closed" on the content
		});
	}
	
		
	// dropdown menu
	var $menu = $('#nav');		
	$menu.children('li').each(function(){
		var $this = $(this);

		var submenu = $this.find('.dropdown_submenu');
		if (submenu.length) {
			submenu.parents('ul, div').css('z-index', 700); // (old value = 2000) z-index hack for IE7
			$this.bind('mouseenter',function(){
				
				submenu.stop(true,true);
				submenu.slideDown().css('z-index', 500); // (old value = 1000) z-index hack for IE7
				
			}).bind('mouseleave',function(){
				submenu.fadeOut('fast');
			});
		}		
	});
	
}

$().ready(function(){
	


	/**
	 * 
	 * Login Area for the clients and affiliates in the WP footer
	 * 
	 */
	$("#client_affiliate_login_form").ajaxForm({
		dataType: 'json',
		success: function(data){
					
					if (data.result == 'true'){//username and password pair is valid
						window.location = "" + app_base_url + "/" + data.area;
					}else{
						alert(data.message);
					}
					
			}
	})
	
	/**
	 * Print current section:
	 * -- open new window
	 * -- write content
	 * -- print this window
	 * 
	 * 
	 */
	$(".print_button").click(function(){
		
		var section_to_print 		= $(this).attr('section_to_print');
		var section_to_print_title	= $(this).attr('section_to_print_title');
		
		
		w = window.open('','','height=250px,width=250px');
		w.document.write('<html><head><title>' + section_to_print_title + '</title>');
		w.document.write('<link href="' + template_directory + '/css/style.css" rel="stylesheet" type="text/css" />');
		w.document.write('<link href="' + template_directory + '/css/print.css" rel="stylesheet" type="text/css"/>');
		w.document.write('</head><body>');
		w.document.write($('#print_' + section_to_print).html());
		w.document.write('</body></html>');
		w.print();
		w.close();

	})
	
})
