jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null};
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

$(document).ready(function(){
	//JQUERY COOKIE
	var listing_type = $.cookie("listing_type");
	if(listing_type == "listbox"){
	 	$("a.listbox").addClass("listbox_active");
		$("a.listexp").removeClass("listexp_active");
        $(".entry-content .preview_base").addClass("colpreview").removeClass("preview_base"); 
    }
	if(listing_type == "listexp"){
		$("a.listexp").addClass("listexp_active");
	 	$("a.listbox").removeClass("listbox_active");
        $(".entry-content .colpreview").addClass("preview_base").removeClass("colpreview");
	}
	//JQUERY COOKIE
	
	
	
	$("#myController").jFlow({
		slides: "#mySlides",
		width: "100%",
		height: "255px",
		duration: 400
	});
$('#mycarousel').jcarousel();
	// SIDEBAR BANNER
	if($("#getadvice")){
		var randomnumber=Math.floor(Math.random()*2)
		$("#getadvice").children('div').hide();
		$("#getadvice").children('div.banner'+randomnumber).show();
	}
		if($("#testimonial")){
		var randomnumber=Math.floor(Math.random()*2)
		$("#testimonial").children('div').hide();
		$("#testimonial").children('div.speek'+randomnumber).show();
	}

	//	TOP NAVIGATION *****
		$("#menu-top_menu > li").each(function(){
			if($(this).children("ul").length >0){
//				$(this).children('a').attr('href','#');
				$(this).children('a').addClass('expand');
				$('ul.sub-menu').css('display','block')
				$(this).children('ul').wrap('<div class="subnav">');
			}
		 })

		$("a.expand").each(
			function( intIndex ){
				$(this).bind ("click",function(e){
					if(!$(this).is('.active')){
						$("a.expand").removeClass('active')
						$("a.expand").parent().children('div').hide();
						$(this).addClass('active')
						if ($.browser.msie && $.browser.version.substr(0,1)<7) {
							$(this).parent().children('div').show();
						}else{
							$(this).parent().children('div').fadeIn();
						}
					}else{
						$(this).removeClass('active')
						$(this).parent().children('div').hide();
					}
					e.preventDefault();
				});
		});
		$("div.subnav").each(function (i) { $(this).hide();});
		$(document).click(function(){$(".subnav").hide();$("a.expand").removeClass('active')});
		$(".subnav a").click(function(){$(".subnav").hide();$("a.expand").removeClass('active')});
		$("a.expand").parent().click(function(e){e.stopPropagation();});
	//	TOP NAVIGATION *****
	setSt=0;swapSlidesT="";headI01="#header01";headI02="#header02";canStart="no";
	img1='latest01';img2='latest02';
	swapSlides = function(){
		if(setSt==0){img1='latest01';img2='latest02';setSt=1;
		}else{img1='latest02';img2='latest01';setSt=0;
		}
		var myTimer = {};
		$(headI02+"_logo").animate({"left": "+=200px", "opacity": 0}, 1000, function() {
			$(headI02+"_logo").css('background-image', 'url(/wp-content/themes/theme01/images/'+img1+'_logo.png)');
		});
		
		myTimer = $.timer(400,function(){
			$(headI01+"_logo").animate({"left": "+=260px", "opacity": 0}, 1000, function() {
				$(headI01+"_logo").css('background-image', 'url(/wp-content/themes/theme01/images/'+img2+'_logo.png)');
			});
		});		
		myTimer = $.timer(1200,function(){$(headI02+"_logo").animate({"left": "-=200px", "opacity": 1}, 1000);});		
		myTimer = $.timer(1500,function(){$(headI01+"_logo").animate({"left": "-=260px", "opacity": 1}, 1500);});		
		// Large image animate
		$(headI01+"C").css('opacity', '0');$(headI02+"C").css('opacity', '0');
		$(headI01+"C").css('background-image', 'url(/wp-content/themes/theme01/images/'+img2+'.png)');
		$(headI02+"C").css('background-image', 'url(/wp-content/themes/theme01/images/'+img1+'.png)');

		$(headI02).animate({"opacity": 0}, 1500, function() {$(headI02).css('background-image', 'url(/wp-content/themes/theme01/images/'+img1+'.png)');});
		
		$(headI01).animate({"opacity": 0}, 1500, function() {
			$(headI01).css('background-image', 'url(/wp-content/themes/theme01/images/'+img2+'.png)');
			$(headI02).animate({"opacity": 1}, 1500);
			$(headI01).animate({"opacity": 1}, 1500);
		});
		
		$(headI01+"C").animate({"opacity": 1}, 2500);$(headI02+"C").animate({"opacity": 1}, 2500);
	}
	$(headI02).click(function () {
		if(canStart=="yes"){clearInterval(swapSlidesT);if($(headI01).is(":animated") || $(headI02).is(":animated")){}else{swapSlides();}}
	});
	$(headI02+"_logo").click(function () {
		if(canStart=="yes"){clearInterval(swapSlidesT);if($(headI01).is(":animated") || $(headI02).is(":animated")){}else{swapSlides();}}
	});

	// loading
	var im1 = new Image();var im2 = new Image();
	$(headI01).animate({"opacity": 0}, 0);$(headI02).animate({"opacity": 0}, 0);
	$(im1).load(function () {
		$(this).css('display', 'none');$('div.loading').fadeOut();
		$(headI01).css('background-image', 'url(/wp-content/themes/theme01/images/'+img1+'.png)')
		$(headI01).animate({"opacity": 1}, 1000);

			$(im2).load(function () {
				$(this).css('display', 'none');
				$(headI02).css('background-image', 'url(/wp-content/themes/theme01/images/'+img2+'.png)')
				$(headI02).animate({"opacity": 1}, 1000);
				canStart="yes"
				swapSlidesT=setInterval("swapSlides()", 10000);
			}).error(function () {
			}).attr('src', '/wp-content/themes/theme01/images/'+img2+'.png')

	}).error(function () {
	}).attr('src', '/wp-content/themes/theme01/images/'+img1+'.png')

	// PORTFOLIO DETAIL SCRIPT
//	-65px
$("div.preview a").mouseover(function(){$("div.preview_desc").animate({"bottom": "+5px", "opacity": .7}, 1000);})
$("div.preview a").mouseout(function(){
		$("div.preview_desc").animate({"bottom": "-65px", "opacity": 0}, 1000) 
;})
	tThumbs=$('a.thumb').length;
	$('a.thumb').each(function(){				
//		var src1= t.attr('src'); // initial src
//		var newSrc = src1.substring(src1.lastIndexOf('/')+1, src1.lastIndexOf('.')); // let's get file name without extension
			$(this).click(function(){
				var img=$(this).children('img');
				var rel=img.attr('rel');
				$('a.thumb').parent().removeClass("current");
				$(this).parent().addClass("current")

				$("div.preview a img").fadeOut("slow", function(){
				$("div.preview a img").attr('src', rel)
				$("div.preview a img").fadeIn();
			});
		});
	});


// Input Button
		$("form").find('input.button').each(function(i){
			$(this).mouseover(function() { $(this).addClass("button_hover");})
			$(this).mouseout(function() { $(this).removeClass("button_hover");});
		;});

// Payment Expand Collapse
$(".expD").hide();
	$(".expD").eq(0).show();
	$("h2.expand").click(function(){
		curr=$(this);
		$("h2.expand").each(function(i){
			$(this).next().slideUp('fast', function(){curr.next().slideDown();});
		});
	});

// portfolio Preview change type
//alert($(".preview_base").attr('class'));
    $("a.listbox").click(function(){
	 	$(this).addClass("listbox_active");
		$.cookie("listing_type", "listbox", { path: '/' });
		$("a.listexp").removeClass("listexp_active");
        $(".preview_base").addClass("colpreview").removeClass("preview_base");

    }); 
	 $("a.listexp").click(function(){
		$(this).addClass("listexp_active");
		$.cookie("listing_type", "listexp", { path: '/' });
	 	$("a.listbox").removeClass("listbox_active");
        $(".colpreview").addClass("preview_base").removeClass("colpreview"); 
	});
});
