/*
site: baralaye.com
author: Ebitenyefa Baralaye
*/
	
(function($){$(document).ready(function(){

//// Global variables
Loc=document.location.href;
breadcrumb=$('#breadcrumb');
Dir0 = Loc.split('/')[3];
Dir1 = Loc.split('/')[4];
Dir2 = Loc.split('/')[5];
Dir3 = Loc.split('/')[6];
Uns1 = Loc.split('_')[1];

// Nav copy over
$('#BottomNav').html($('#TopNav').html());

//// Fancy Box code
$('a#gMap').fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});
//alert("2");
$('a.ltbx').fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});
$('.ltbx').each(function(){$(this).children('a').eq(0).fancybox({'transitionIn':'elastic','transitionOut':'elastic','speedIn':600,'speedOut':200,'overlayShow':true});});
$('a.ltbx.win').fancybox({'width':400,'height':400,'autoDimensions':false});
$('a.ltbx.gMap').fancybox({'width':400,'height':400,'autoDimensions':false});
$('.ltbx.win').each(function(){$(this).children('a').eq(0).fancybox({'width':400,'height':400,'autoDimensions':false});});



//// Cloud zoom
if ($('#zoom-var').text()=="zoom-1"){
	var main_rel ="position: 'inside'";
	var catalog = $('.shop-product-large .image img:first').attr('src').split('/')[4];
	var imgFirst_name = $('.shop-product-large .image img:first').attr('src').split('/')[6]; 
	$('.shop-product-large .image img:first').wrap("<a href='/images/art/portfolio/"+catalog+"/big/"+imgFirst_name+"' class='cloud-zoom' id='zoom1' />");
	$('.shop-product-large .image a:first').attr('rel',main_rel);
	$('.productPopletsItem a').each(function(){
		var img_name = this.href.split('/')[8];
		var url_rel = "useZoom: 'zoom1', smallImage: '/images/art/portfolio/"+catalog+"/large/"+img_name+"'";
		var big_src = "/images/art/portfolio/"+catalog+"/big/"+img_name; 
		$(this).removeAttr('onclick').attr('rel',url_rel).attr('class','cloud-zoom-gallery').attr('href',big_src);
	});
}

//// Add class to page wrap in post detail view ////
if(Loc.split('/')[4]=="Blog" && (Loc.split('/')[5]=="post")){
	$('#Wrap').addClass('post-detail');
}

//// Inner Fade ////
setTimeout(function(){ // set with delay for the above script to render width dimensions before display:none is applied to imgs. 
$('.innerfade').innerfade({
	animationtype: 'fade',
	speed: 2000,
	timeout: 20000,
	type: 'random',
	//containerheight: '900px'
});
}, 250);

setTimeout(function(){$('.innerfade').animate({opacity:1},2000)}, 500);



	
//// Portal Accordion Slides
if(Dir0==""){
	var slide_number; 
	function slideNumber(slides){
		slide_number = Math.floor(Math.random() * slides);
	}
	
	var slides_inProgress = new Array("/images/art/portfolio/in-progress/Barabbas_a.jpg","/images/art/portfolio/in-progress/Kahn_a.jpg","/images/art/portfolio/in-progress/Untitled-1_a.jpg");
	slideNumber(slides_inProgress.length);
	$('.home .accordion .in-progress img').attr('src',slides_inProgress[slide_number]);
	
	var slides_sculpture = new Array("/images/art/portfolio/sculpture/large/Abram_1a.jpg","/images/art/portfolio/sculpture/large/Lazarus_1a.jpg","/images/art/portfolio/sculpture/large/Kesiye_a.jpg","/images/art/portfolio/sculpture/large/Adesuwa_a.jpg","/images/art/portfolio/sculpture/large/Jehoakim_a.jpg","/images/art/portfolio/sculpture/large/Hughes_a.jpg");
	slideNumber(slides_sculpture.length);
	$('.home .accordion .sculpture img').attr('src',slides_sculpture[slide_number]);
	
	var slides_vessels = new Array("/images/art/portfolio/vessels/large/Vaughan_1a.jpg","/images/art/portfolio/vessels/large/Miles_1a.jpg","/images/art/portfolio/vessels/large/Fuji_2a.jpg");
	slideNumber(slides_vessels.length);
	$('.home .accordion .vessels img').attr('src',slides_vessels[slide_number]);
	
	var slides_drawings = new Array("/images/art/portfolio/drawings/large/sketch_1.jpg","/images/art/portfolio/drawings/large/sketch_4.jpg","/images/art/portfolio/drawings/large/sketch_9.jpg");
	slideNumber(slides_drawings.length);
	$('.home .accordion .drawings img').attr('src',slides_drawings[slide_number]);
	
	var slides_photography = new Array("/images/art/portfolio/photography/large/photo_LIC_bench_1.jpg","/images/art/portfolio/photography/large/photo_LIC_cone.jpg","/images/art/portfolio/photography/large/photo_LIC_rubble_pile.jpg");
	slideNumber(slides_photography.length);
	$('.home .accordion .photography img').attr('src',slides_photography[slide_number]);
	
	//// Portal Accordion ////
	$('.accordion').classicAccordion({
		width:675, height:200, slideshow:false, shadow:true, alignType:'centerCenter', closedPanelSize:60, panelProperties:{
			0:{captionTop:162, captionLeft:-1, captionWidth:200, captionHeight:38},
			1:{captionTop:162, captionLeft:-1, captionWidth:200, captionHeight:38},
			2:{captionTop:162, captionLeft:-1, captionWidth:200, captionHeight:38},
			3:{captionTop:162, captionLeft:-1, captionWidth:200, captionHeight:38},
			4:{captionTop:162, captionLeft:-1, captionWidth:200, captionHeight:38},
			5:{captionTop:162, captionLeft:-1, captionWidth:200, captionHeight:38}
		}
	});
}
	
/*
else if(Dir0=="in-progress"){ // in-progress page
	var flashvars={};
	var params={play:"true",loop:"false",scale:"noscale",salign:"tl",quality:"high",wmode:"transparent",allowfullscreen:"true",allowscriptaccess:"always"};
	var attributes={};
	swfobject.embedSWF("/flash/gallery.swf","gallery","900","450","9.0.0",false,flashvars,params,attributes);
}
*/

//// Nav
$('#TopNav a').each(function(){;
	var SubA=$(this);
	var SubL=this.href;
	var sDir0 = SubL.split('/')[3];
	var sDir1 = SubL.split('/')[4];
	var sHsh = SubL.split('#')[1];
	if (SubL==Loc || (sDir0==Dir0 && sHsh==null) || SubA.html()==breadcrumb.html() || ($('#Account')!=null && (sDir0=="Account" && sDir1=="") || (Dir0.substring(0,12)=="CaseRetrieve" && sDir1=="Case_History.htm") || (Dir0.substring(0,19) == "OrderSecureRetrieve" && sDir1 == "Order_History.htm")) || (sDir0=="Store" && (Uns1=="catalog" || Loc.split('_')[1]=="product" || Dir0.substring(0,13)=="OrderRetrieve" || Dir0.substring(0,17)=="CatalogueRetrieve")) || (sDir1== "FAQs.htm" && (Dir0.substring(0,11)=="FAQRetrieve" || Dir0.substring(15,18)=="FAQ"))) {
		$(this).attr('class', 'active');
		$(this).parents('li').attr('class', 'selected')
	}
});

////Light Box
$('.page-body.in-progress .productItem.a .image a').lightBox();
$('.page-body.in-progress .productItem.b .image a').lightBox();
$('.page-body.in-progress .productItem.c .image a').lightBox();
$('.page-body.in-progress .productItem.d .image a').lightBox();
$('.page-body.in-progress .productItem.e .image a').lightBox();
$('.page-body.in-progress .productItem.f .image a').lightBox();

//// Top nav rollover
$('#TopNav > div > ul > li ').mouseover(function(){
	$(this).siblings().removeClass('selected');
	$(this).addClass('selected');
	$(this).mouseleave(function(){
		$(this).removeClass('selected');
	});
});

///// Text field clear on type
$('input.field').click(function(){
	$(this).attr('value','');
});


//// Background image rotator
var Rotator = new Array() 
Rotator[0] = "sketch0.gif";
Rotator[1] = "sketch1.gif";
Rotator[2] = "sketch2.gif";
Rotator[3] = "sketch3.gif";
Rotator[4] = "sketch4.gif";
var whichRotator = Math.floor(Math.random()*(Rotator.length))
$('#bg_img').height($('#Wrap').outerHeight());
var img_src = 'url(/images/bg/' + Rotator[whichRotator] + ')';
$('#bg_img').css('background-image', img_src);

//// Hide product price (for items not for sale)
if($('.shop-product-large .specs .stock').html()=='0'){
$('.shop-product-large .specs .price a').html('inquire');
}
$('.shop-product-large .specs .price').show('slow');
//$('.shop-product-large .details li.purchase').hide();

//// Hide product edition (for inapplicable items)
if($('.shop-product-large .specs .edition span').html()==''){
$('.shop-product-large .specs .edition').hide();
}

//// Hide product wieght (for inapplicable items)
if($('.shop-product-large .specs li.weight span:first').html()!="") $('.shop-product-large .details li.weight').show();

//// Hide "Cart Empty" text
if ($('td.cartSummaryItem').html()=="Shopping cart is empty.") $('td.cartSummaryItem').html('');
$('#catCartSummary').show();

//// gMap Google Map function
$('.gMap').click(function(){
var addr = $(this).attr('title');
var tag = $(this).html();
$("#gMap").gMap({ markers: [{ address: addr, html: tag }], zoom: 15});
});

///// Flicker Photoset function
				$('.productSmall.photoset').each(function(){
				jQuery('<img />').attr('class', 'loader').attr('src', '/images/plugin/ajax-loader.gif').appendTo('.productSmall.photoset');
                //assign your api key equal to a variable
                
                var photoSetCont = $(this);
                
                var apiKey = '2dc0ff4d2daaa11adcdef83d127b8558';
                
                var photosetID = $(this).attr('id').split('_')[1];
                //the initial json request to flickr
                //to get your latest public photos, use this request: http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=' + apiKey + '&user_id=29096781@N02&per_page=15&page=2&format=json&jsoncallback=?
				$.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=' + apiKey + '&photoset_id=' + photosetID + '&format=json&jsoncallback=?',
                function(data){
                    
                    //loop through the results with the following function
                    $.each(data.photoset.photo, function(i,item){
                    
                        //build the url of the photo in order to link to it
                        var photoURL_m = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_m.jpg';
                        var photoURL_b = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_z.jpg';
                        
                        //turn the photo id into a variable
                        var photoID = item.id;
                        
                            //use another ajax request to get the tags of the image
                            $.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photos.getInfo&api_key=' + apiKey + '&photo_id=' + photoID + '&format=json&jsoncallback=?',
                            function(data){
                                
                            //create an imgCont string variable which will hold all the link location, title, author link, and author name into a text string
                            var imgCont = '<li class="productItem"><div class="image"><a href='+ photoURL_b +' title='+ data.photo.title._content +'><img src='+ photoURL_m +' alt='+ data.photo.title._content +' /></a></div>';
                            
                            //add the description & html snippet to the end of the 'imgCont' variable
                            imgCont += '<div class="image-info"><h4 class="title">'+data.photo.title._content+'</h4><p class="desc">'+data.photo.description._content+'</p></div></li>';
                            
                            //append the 'imgCont' variable to the document
                            $(imgCont).appendTo( photoSetCont );
                             
                                  
                                  
                               /*                                                             $('.productItem').each(function(){
           if($(this).find('.title').html() != ""){ 
        	if($(this).find('.desc').html() != "") $('.productItem .desc').show();
            $(this).mouseenter(function(){
                $(this).find('.image-info').show();
            });
            $(this).mouseleave(function(){
                $(this).find('.image-info').hide();
            });
         }
    });
    */
                     //Activate Lightbox             
                $('.productSmall.photoset a').lightBox();
                
                        });
                        
                	});
                	
                });


                jQuery('.loader').remove();
            });


})})(jQuery);
