


//Ad Slider//
 	$('.adslider').cycle({
		fx: 'fade',
		timeout: 6000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	$('.adslider2').cycle({
		fx: 'fade',
		timeout: 8000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	$('.banner_adslider').cycle({
		fx: 'fade',
		timeout: 8000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});


	function search(e){

			var _qry = document.getElementById('criteria').value;

			//$.post('/search/index/'+escape(_qry)+'/0/25', {qry: _qry},function(data){
			//  		$('.maincontent').html(data);
			//	}
			//);
			_qry = _qry.replace(/\s+/gi,'-');
			location.href='/search-'+escape(_qry);
			
	}		
	
	function search_page(e, _offset, _limit){

			var _qry = document.getElementById('criteria').value;

			$.post('/search/index/'+escape(_qry)+'/'+_offset+'/'+_limit, {qry: _qry},function(data){
			  		$('.maincontent').html(data);
				}
			);
			
			window.scrollTo(0,0);
			
	}		
	

	function ad_jump(e, _qry){
		
				var _qry = document.getElementById('criteria').value=_qry;
				search(e);
	}	
	
	


$(document).ready(function() {
    $('a.button').click(function () {
        $('#dialog-overlay, #dialog-box').hide();
        return false;
    });
    
    
    //enable enter key press for search//
    $('#criteria').bind('keypress', function(e) {
        if(e.keyCode==13){
                search(e);
        }
	  });		 
	  	  
    //jquery popup
    $('.popup').popupWindow({ 
    	height:500, 
    	width:960, 
    	top:50, 
    	left:50 
    }); 
    	 

    $(window).resize(function () {

        //only do it if the dialog box is not hidden
        
        // get the screen height and width 
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        // calculate the values for center alignment
        var dialogTop = (maskHeight / 3) - ($('#dialog-box').height());
        var dialogLeft = (maskWidth / 2) - ($('#dialog-box').width() / 2);

        var position = (rank - 1) * 75;

        // assign values to the overlay and dialog box
        $('#dialog-overlay').css({ height: maskHeight, width: maskWidth }).show();
        $('#dialog-box').css({ top: dialogTop + position, left: dialogLeft, width: '500px', height: '300px' }).show();
        if (!$('#dialog-box').is(':hidden')) popup();
    }); 

        $('.slideshow').cycle({
            fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        });

        var name = $("#name"),
			email = $("#email"),
			password = $("#password"),
			allFields = $([]).add(name).add(email).add(password),
			tips = $(".validateTips");

        function updateTips(t) {
            tips
				.text(t)
				.addClass("ui-state-highlight");
            setTimeout(function () {
                tips.removeClass("ui-state-highlight", 1500);
            }, 500);
        }

        function checkLength(o, n, min, max) {
            if (o.val().length > max || o.val().length < min) {
                o.addClass("ui-state-error");
                updateTips("Length of " + n + " must be between " +
					min + " and " + max + ".");
                return false;
            } else {
                return true;
            }
        }

        function checkRegexp(o, regexp, n) {
            if (!(regexp.test(o.val()))) {
                o.addClass("ui-state-error");
                updateTips(n);
                return false;
            } else {
                return true;
            }
        }

        $("#dialog-form").dialog({
            autoOpen: false,
            height: 300,
            width: 350,
            modal: true,
            buttons: {
                "Login": function () {
                    var bValid = true;
                    allFields.removeClass("ui-state-error");

                    //bValid = bValid && checkLength( name, "username", 3, 16 );
                    //bValid = bValid && checkLength(email, "email", 6, 80);
                    bValid = bValid && checkLength(password, "password", 5, 16);

                    //bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
                    // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
                    //bValid = bValid && checkRegexp(email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com");
                    bValid = bValid && checkRegexp(password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9");

                    if (bValid) {
                        updateTips('Thank you!');
                        $(this).dialog("close");
                        document.getElementById('frmLogin').submit();

                    }
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            },
            close: function () {
                allFields.val("").removeClass("ui-state-error");
            }
        });

        $("#create-user")
        //.button()
			.click(function () {
			    $("#dialog-form").dialog("open");
			});
        //On Hover Over
        $('#nav li').hover(
        function () {
            //show its submenu
            $('ul', this).slideDown(100);

        },
        function () {
            //hide its submenu
            $('ul', this).slideUp(100);
        }
    );

    
	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
 
	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	}); 
       
    });


   

    /*
    var $dialog = $('<div></div>')
    .load('cdetails.asp?id=' + id + '&m=' + m)
    .dialog({
    autoOpen: false,
    height: 600,
    width: 750,
    modal: true,
    title: 'Coupon Details'
    });

    $('#opener').click(function () {
    $dialog.dialog('open');
    // prevent the default action, e.g., following a link
    return false;
    });

    /*
    function getDetails(id, m) {
    document.getElementById('second_page').innerHTML = 'Loading...';
    $(function () {
    $("#second_page").dialog({
    autoOpen: false,
    height: 600,
    width: 750,
    modal: true
    });
    alert('cdetails.asp?id=' + id + '&m=' + m);
    $("#second_page").load('cdetails.asp?id=' + id + '&m=' + m);
    $("#second_page").dialog("open");
    });
    }
    */

function pop_up(hyperlink, window_name)
	{
		if (! window.focus)
			return true;
		var href;
		if (typeof(hyperlink) == 'string')
			href=hyperlink;
		else
			href=hyperlink.href;
		window.open(
			href,
			window_name,
			'width700,height=500,toolbar=yes, scrollbars=yes'
		);
		return false;
	}


/* Navigation Dropdown */

	
	//nav style1//
	function nav1_over(){
		$(this).css('background-position','0px -48px');
				
		$(this).find('div.menucnt').css('position','absolute');		
		$(this).find('div.menucnt').css('display','block');
	}
	
	function nav1_out(){
		$(this).find('div.menucnt').css('display','none');
	}		
	

		
	
	$(document).ready(function(){
	
	
	//nav style1//
	var config_nav1 = {    
     over: nav1_over,  
     timeout: 0,    
     out: nav1_out   
	};

	$("#menu li.more").hoverIntent( config_nav1 );	
	
	

	});
/* End Navigation Dropdown */
	
// This adds 'placeholder' to the items listed in the jQuery .support object. 
jQuery(function() {
   jQuery.support.placeholder = false;
   test = document.createElement('input');
   if('placeholder' in test) jQuery.support.placeholder = true;
});
// This adds placeholder support to browsers that wouldn't otherwise support it. 
$(function() {
   if(!$.support.placeholder) { 
      var active = document.activeElement;
      $(':text').focus(function () {
         if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
            $(this).val('').removeClass('hasPlaceholder');
         }
      }).blur(function () {
         if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
            $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
         }
      });
      $(':text').blur();
      $(active).focus();
      $('form:eq(0)').submit(function () {
         $(':text.hasPlaceholder').val('');
      });
   }
});
	
	
	
	

