/* Custom fonts */

Cufon.replace('#nav_1232603 a,h1,#footer h4,.boxE_title,.temp_name,.selectBox_leftpannel span,.wrap_form h2',{hover:true});

/*** custom plugins version 2.0 features ***/
	(function(jQuery){
		/*** this is for the menu of about us ***/
		jQuery.fn.moving_menu = function(){
			var p = jQuery(this);
				p.draggable({containment:'.side_menu',axis:'y'});
		}
		
		/*** this is for mobile design principles simple accordion ***/
		jQuery.fn.mobile_accordion = function(events){
			var setEffects = {data:'true',attributes:'false'};
			var events = jQuery.extend(setEffects,events);
			var prnts = jQuery(this);
				prnts.click(function(e){
					e.preventDefault();
					jQuery(this).next().slideToggle('slow');
						var co = jQuery("ul.mobile_accordion a").index(this);
						jQuery("ul.mobile_accordion a").each(function(a,b){
							if(co == a){
								jQuery(this).addClass('selected');
							}else{
								jQuery(this).removeClass('selected').next().slideUp('slow');
							}
						});

				return false;
			});	
		}
		
		/*** this is for mobile design add class to every 4 ***/
		jQuery.fn.putClass = function(eventoptions){
			var getAttribute = {source:".mobile_gal",size:'3'};
			var eventoptions = jQuery.extend(getAttribute,eventoptions);
			var p = jQuery(this);
				return p.each(function(b){
					var setval = b+1;
					if(setval%4==1){
					var getRows = b + eventoptions.size;
						jQuery(eventoptions.source+":eq("+getRows+")").addClass('nM-R');
					}
				});  
		}
		
		/*** this is for the our team sliding menu scripts ***/
		jQuery.fn.dragmenow = function(eventoptions){
		   var setups = {min:'#m_designteam',mid:'#m_devteam',max:'#m_seo',speed:'slow',duration:'fast',showmin:'.designB a',showmid:'.webdevB a',showmax:'.seo a'};
		   eventoptions = jQuery.extend(setups,eventoptions);
		   var parental = jQuery(this);
			parental.mousemove(function(e){
			   var taketop = parseInt(jQuery(this).css('top'));
			   setTimeout(function(){
					if(taketop > 0 && taketop < 21){
						jQuery(eventoptions.min).fadeIn(eventoptions.speed);
						jQuery(eventoptions.mid).hide(eventoptions.duration);
						jQuery(eventoptions.max).hide(eventoptions.duration);
						jQuery(eventoptions.showmin).addClass('selected');
						
						jQuery(eventoptions.showmid).removeClass('selected');
						jQuery(eventoptions.showmax).removeClass('selected');
						
					}else if(taketop > 117 && taketop < 159){	  
						jQuery(eventoptions.mid).fadeIn(eventoptions.speed);
						jQuery(eventoptions.min).hide(eventoptions.duration);
						jQuery(eventoptions.max).hide(eventoptions.duration);
						jQuery(eventoptions.showmid).addClass('selected');
						
						jQuery(eventoptions.showmin).removeClass('selected');
						jQuery(eventoptions.showmax).removeClass('selected');
						
					}else if(taketop > 159){
						jQuery(eventoptions.max).fadeIn(eventoptions.speed);
						jQuery(eventoptions.min).hide(eventoptions.duration);
						jQuery(eventoptions.mid).hide(eventoptions.duration);
						jQuery(eventoptions.showmax).addClass('selected');
				
						jQuery(eventoptions.showmin).removeClass('selected');
						jQuery(eventoptions.showmid).removeClass('selected');
					}
				},500);
			});
		}
		
		/*** this is for mobile web gallery list overlay ***/
		jQuery.fn.mobileOverlay = function(events){
			var setups = {classOf:'.mobileShow',effects:'drop'};
			events = jQuery.extend(setups,events);
			var parnt = jQuery(this);
				parnt.hover(function(){
					jQuery(this).children(events.classOf).show(events.effects,{},"slow");
				},function(){
					jQuery(this).children(events.classOf).hide();
				});
		}
		
	})(jQuery);
/*** end custom plugins version 2.0 ***/

	/*** this is for adding last class to index what we do ***/
	function what_we_do(){
		jQuery("#wat_do .boxA_body:last").addClass('boxA_cont');
		jQuery("#sol_abc .boxB_body:last").addClass('boxB_cont');
		jQuery("#overall_templtes .boxE_body:last").addClass('boxE_cont');
	}
	
	/*** this is for adding class in every 3rd li for the list of businesscatalyst certified list description ***/
	function certified_businesscatalyst(){
		jQuery("ul#certified_bc_list li").each(function(b){
			var b = b+1;
			var a = b%3;
				if(b%3==1){
					var c = b +1;
					jQuery("ul.boxG_body li:eq("+c+")").addClass('nM-R');
				}
		});
	}
	
	/**** custom slider hover effects *****/
	function moving_mobileMenu(){
		var $locators = {mobile:"27",design:"347",gallery:"668"};
		//jQuery("#mobile_movers").animate({marginLeft:$locators.mobile+"px"},'slow');
		jQuery("#nav_1232837 li").hover(function(){
			var $Chrispush = jQuery(this).attr('class');
			if($Chrispush !==""){
				switch($Chrispush){
					case "phone":
							jQuery("#mobile_movers").animate({marginLeft:$locators.mobile+"px"},'slow');
							jQuery(this).find('span').css('color','#fff !important');
					break;
					case "design":
							jQuery("#mobile_movers").animate({marginLeft:$locators.design+"px"},'slow');
							jQuery(this).find('span').css('color','#fff !important');
					break;
					case "gallery":
						 	jQuery("#mobile_movers").animate({marginLeft:$locators.gallery+"px"},'slow');
							jQuery(this).find('span').css('color','#fff !important');
					break;
				}
			}
		},function(){
			//jQuery(this).find('span').css('color','#A6C9DE');
		});
	}

	/*** hidden features for mobile hoverings ***/
	function prototype_mobileSlide(){
		jQuery("#cat_1232837_divs").attr('id','tetew');
			jQuery("#mobile_movers").draggable({axis:'x',containment:'.mobile_menu'});
			jQuery("#mobile_movers").css({'left':'27px','cursor':'pointer'});
				jQuery("#mobile_movers").mousemove(function(e){
					var a = parseInt(jQuery(this).css('left'));

					if(a > 295 && a < 435){
						jQuery("#hv_design").fadeIn('slow');
						jQuery("#hv_gallery,#hv_mobile").hide('fast');
						jQuery(".design span").css('color','#fff');
						jQuery(".phone span,.gallery span").css('color','#A6C9DE');
					}else if(a > 0 && a < 295){
						jQuery("#hv_mobile").fadeIn('slow');
						jQuery("#hv_gallery,#hv_design").hide('fast');
						jQuery(".phone span").css('color','#fff');
						jQuery(".design span,.gallery span").css('color','#A6C9DE');
					}else if(a > 435){
						jQuery("#hv_gallery").fadeIn('slow');
						jQuery("#hv_design,#hv_mobile").hide('fast');
						jQuery(".gallery span").css('color','#fff');
						jQuery(".design span,.phone span").css('color','#A6C9DE');
					}
				});
	}
	
	/*** revised moving_mobileMenu2 for Qa ***/
	function moving_mobileMenu2(){
		var $locators = {phone:"27",design:"347",gallery:"668"};
		var t;
		jQuery("#mobile_movers").css({"marginLeft":"0","left":"27px"});
		jQuery("#nav_1232837 li").hover(function(){
			var coco = jQuery(this).attr('class');
			   t = setTimeout(function(){
				if(coco == 'phone'){
					coco = $locators.phone;
					jQuery("#hv_mobile").fadeIn('slow');	
					jQuery("#hv_design,#hv_gallery").hide('fast');
				}else if(coco =='design'){
					coco = $locators.design;
					jQuery("#hv_design").fadeIn('slow');
					jQuery("#hv_mobile,#hv_gallery").hide('fast');
				}else if(coco =='gallery'){
					coco = $locators.gallery;
					jQuery("#hv_gallery").fadeIn('slow');
					jQuery("#hv_mobile,#hv_design").hide('fast');
				}
				jQuery("#mobile_movers").animate({left:coco+"px"},'slow');
				jQuery(this).find('span').css('color','#fff !important');			
			},400);
		},function(){
			//jQuery(this).find('span').css('color','#A6C9DE');
		clearTimeout(t);
		});
	}
	
	
	/**** this is for the type of menu ie(starter,professional) ****/
	function moving_choosePlans(){
		var $templatesCat = {starter:'0',professional:'169'};
		var takeActive = jQuery(".profT").hasClass('selected');
		var takeNextActive = jQuery("#startT").hasClass('selected');
		var totPro = (takeActive == true) ? jQuery("#choosen_plan_movers").css({marginLeft:$templatesCat.professional+'px'}) : '';
		var totStar = (takeNextActive == true) ? jQuery("#choosen_plan_movers").css({marginLeft:$templatesCat.starter+'px'}) : '';
			jQuery("#nav_1232622 li").hover(function(){
				var $getActive = jQuery(this).attr('id');
				if($getActive =="startT"){
					jQuery("#choosen_plan_movers").animate({marginLeft:$templatesCat.starter+'px'},'slow');
				}else if($getActive == 'profId'){
					jQuery("#choosen_plan_movers").animate({marginLeft:$templatesCat.professional+'px'},'slow');
				}
			});			
	}
	
	/**** for product list sections only ****/
	function product_previewTooltip(){
		jQuery(".productList").attr("id","p_starter");
	}
    function catalog_previewTooltip(){
		jQuery(".catalogueList").attr("id","p_starter");
	}
	
	/*** this for the product details script ****/
	function product_details(){
		return jQuery("#products_nestedList").removeClass('templates');
	}
	
	/*** interested in pass to another form ****/
	function product_details_viewinterest(){
		var Url_insterested = window.location;
		var Url_setData = jQuery("#prod_interestFile").attr('href');
		var $takefiles = Url_setData+"?interested="+Url_insterested;
		jQuery("#prod_interestFile").attr('href',$takefiles);
	}
	
	/*** get Url ***/
	function gup( name ){
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}
	
	/*** put value url on the interested form ***/
	function get_InterestedWebsite(){
		var Interested =  gup('interested');
		if(Interested !==""){
			return jQuery("input[id^='CAT_Custom_220013']").val(Interested);
		}else{
			return false;
		}
	}
	
	/*** this is only a prototype for enhancement of the mobile pages ***/
	function ultimate(){
			jQuery("ul#nav_1232837 li").hover(function(){
		   var hass = jQuery(this).attr('class');
			switch(hass){
				case "phone":
					jQuery("#hv_mobile").fadeIn('slow');
					jQuery("#hv_design,#hv_gallery").hide();
				break;
				case "design":
					jQuery("#hv_design").fadeIn('slow');
					jQuery("#hv_mobile,#hv_gallery").hide();
				break;
				case "gallery":
				 jQuery("#hv_gallery").fadeIn('slow');
					jQuery("#hv_design,#hv_mobile").hide();
				break;
			}
		  
		});	
	}
	
	/*** this script is for favorites ****/
	function fav_tolike(){
		jQuery(".favoritelink").click(function(e){
			if(sl == 0){
				e.preventDefault();
				alert('You must be logged in to add favorites.');
			}
		});
	}
	
	/*** global maxwidth of h1 span ***/
	function define_header_spanwidth(){
		var counteDLetters = jQuery(".cG").text().length;
		var getMAX = {"first":"480px","second":"442px","third":"240px"};
		var getArgs = ["474px","466px","459px","444px","437px","414px","399px","381px","364px","346px","336px","326px","316px","303px","289px","265px","251px","224px"];
			if(counteDLetters >= 9 && counteDLetters < 10){
			   var ddata = "<span style='width:"+getMAX.first+"'></span>";
			   jQuery(".cG").append(ddata);
			}else if(counteDLetters == 11){
				var ddata = "<span style='width:"+getMAX.second+"'></span>";
			   jQuery(".cG").append(ddata);
			}
	}
	
	/*** choose plan hidden features use only in console :p ***/
	function banners_hiddenplan($str){
		if($str == "1"){
			jQuery(".B1,.B2,.B3,.B4,.B5").hide();
				jQuery("#planners_choosers div").each(function(i) {
				jQuery(this).delay(1200*i).fadeIn('slow');
			});
		}else{
			jQuery(".setEffectz").hover(function(){
				var nice = jQuery(this).stop(true,false).animate({'marginTop':'-30px'},'slow');
			},function(){
				jQuery(this).stop(true,false).animate({'marginTop':'0px'},'slow');
			});
		}
		
	}
	
	/*** hidden features just console it :p for webtemplates banner ***/
	function hover_webT(){
		jQuery(".banner").mousemove(function(e){
		jQuery("#tgg_customcursor").css({display:'block',left:e.clientX+"px",top:e.clientY+"px",'margin':'-124px 0 0 -200px'});
			jQuery(".cursor").hide();
		});
		jQuery(".boxD").bind('mouseout',function(e){
			jQuery("#tgg_customcursor").hide();
			jQuery(".cursor").show();
		});
	}
	
	/*** upload scripts ***/
	function checkedme(el){
		var objWrap;
		objWrap = document.getElementById(el.id+"Wrap");
		if(el) {
			if(el.checked) objWrap.className = "chkboxwrap checked";
			else  objWrap.className = "chkboxwrap";
		}
	}
	
	/*** function for forms scripts ***/
	function form_scripts(){
		jQuery(".category").selCust();
	 	jQuery (".fileupload").prepend('<div class="box1"><input type="text" name="filetxt" class="txtup" /><img src="/TGG/images/browse.png" /></div>');
	}
	
	/*** changing span width h1 title ***/
	function change_r_width(){
		var x=0;
			jQuery("h1.cD .cufon").each(function(){
				x=parseInt(jQuery(this).width())+x;
			});

		var newWidth=960-parseInt(x);
			jQuery(".cD span").width(newWidth-20).fadeIn('slow');
			
		var yy = 0;
			jQuery("h1.cA .cufon").each(function(){
				yy=parseInt(jQuery(this).width())+yy;
			});
		var newWidth2=960-parseInt(yy);
			jQuery(".cA span").width(newWidth2-20).fadeIn('slow');
			span_widthDesign();
	}
	
	/*** design template css span width header on h1 ***/
	function span_widthDesign(){
		var x=0;
			jQuery("h1.cG .cufon").each(function(){
				x=parseInt(jQuery(this).width())+x;
			});
		var newWidth=601-parseInt(x);
			jQuery(".cG span").width(newWidth-20).fadeIn('slow');
	}
	
	/*** draggable slide on our team menu ***/
	function draggable_ourTeam(){
		var autoaction;
		jQuery("ul#dragSlide li").hover(function(){
			var getclass = jQuery(this).attr('class');
				autoaction = setTimeout(function(){
					if(getclass == 'designB'){
						jQuery("#about_us_movers").animate({top:'0px'},'slow');
		
						jQuery("#m_designteam").fadeIn('slow');
						jQuery("#m_devteam,#m_seo").hide();
					
					}else if(getclass == 'webdevB'){
						jQuery("#about_us_movers").animate({top:'135px'},'slow');
		
						jQuery("#m_devteam").fadeIn('slow');
						jQuery("#m_designteam,#m_seo").hide('slow');
						
					}else if(getclass == 'seo'){
						jQuery("#about_us_movers").animate({top:'272px'},'slow');
	
						jQuery("#m_seo").fadeIn('slow');
						jQuery("#m_designteam,#m_devteam").hide();
					}
				},500);
				},function(){
					clearInterval(autoaction);
		});
	}
	
	/*** hide unwated css ***/
	function removethis($str){
		return jQuery($str).removeClass('selected');
	}
	
	/*** opacity effects for folio list page ***/
	function opacity_foliolist(){
		jQuery(".folio_attributes").hover(function(){
			jQuery(this).children('.folio_hover').animate({opacity:'0'},'slow');
		},function(){
			jQuery(this).children('.folio_hover').animate({opacity:'0.3'},'slow');
		});
	}
	/** Create Animated Tooltip for Catalogs and Products**/
	function newtooltip(rodclass,idTooltip, idTooltipContent){
	 var ctr = 1;
         var str = idTooltip;
         var str2 = idTooltipContent;
	     jQuery(rodclass).each(function(){
			str = str+ctr;
			str2 = str2+ctr;
			jQuery(this).children(".temp_img").attr("id",str)
			jQuery(this).children(".TGG_website_preview").attr("id",str2)
    		
			var tc = "#"+str;
			var cc = str2;
			var x = ctr % 3;
           if(x == 0){
             jQuery(tc).ezpz_tooltip({
                  contentId: cc,
                  contentPosition: 'belowFollow',
                  offset: '430',
                  showContent: function(content) {
                  content.fadeIn('fast');
                  },
                  hideContent: function(content) {
				content.stop(true, true).fadeOut('fast');
                  }
                  });
           }else{
			  	jQuery(tc).ezpz_tooltip({
                  contentId: cc,
                   contentPosition: 'rightFollow',
                  showContent: function(content) {
                  content.fadeIn('fast');
                  },
                  hideContent: function(content) {
				content.stop(true, true).fadeOut('fast');
                  }
                  });
         }
				
					ctr = ctr + 1;
		 });
       }
		
		jQuery(document).ready(function(){
			what_we_do();
			/*** script code version 1.0 ***/
			product_previewTooltip();
            	catalog_previewTooltip();
				/* product_details_viewinterest(); */
					fav_tolike();
			certified_businesscatalyst();
			
				moving_mobileMenu2();
				moving_choosePlans();
			
						
						/*** this is only the hidden features ***/
							prototype_mobileSlide();
						/*** end of hidden features ****/
							banners_hiddenplan('show');
		
			setTimeout(function(){
				change_r_width();
			},2000);	
			
			/*** my new version 2.0 scripting style :p ***/
			jQuery("#about_us_movers").moving_menu();
			jQuery("ul.mobile_accordion a").mobile_accordion();
		/*	jQuery(".mobile_gal").putClass(); */
			RowNum(4);
			jQuery("#about_us_movers").dragmenow({duration:''});
			
				draggable_ourTeam();
			/*** folio page ***/
			opacity_foliolist();
			jQuery(".folio_cont").putClass({source:'.folio_cont'});

                /** for the activation of web templates menu**/
			var m = jQuery(".slideBtn_cont").hasClass("left");
			if(m){
				jQuery("ul#nav_1232603 li").each(function(){
					var x = jQuery(this).children("a").attr("href");
					if(x == "/web-templates.htm"){
						jQuery(this).addClass("selected");
                                               var x = jQuery(this).children("a").addClass("p7PMmark ");
					}
				})
			}

             		 /** Removes the (P) on the header**/
			   var st = jQuery("h1#nnr2").text();
			   var x = st.search("(P)");
			   if(x > 1){
			    st = st.replace('(P)','');
			   st = st+"<span style='display: inline; width: 646px;'></span>";
			   jQuery("h1#nnr2").html(st);
			   jQuery("h1#nnr2").removeClass("dhide");
			   }

     /* ADDED BY ROD START */
    
	/* Catalog Preview*/
          var x = jQuery(".catalog-preview").hasClass('hide');
          if(x){
			  jQuery(".catalog-preview").each(function(){
			  var cat = jQuery(this).text();
			  var img = "<img src = '"+cat+"'>";
			  jQuery(this).html(img);
			  jQuery(this).removeClass('hide');								   
			   
		     });
	     }	
          
     /* Hides all the Catalog if it is in product large view */
         var y = jQuery(".productList").hasClass("productLarge");
          if(y){
             jQuery("#wrapper").children("#body-template").attr("id","body");
            jQuery(".catalogueList").css("display","none");
            //jquery(".productTable").css("display","none");
             
          }          
	/* new tooltip sytle for catalog and product  preview*/	
	   var c = jQuery("#p_starter").hasClass("catalogueList");
	   if(c){
            jQuery(".catalogueItem").each(function(){
            jQuery(this).addClass('rod');
           });	
	   }
	   var d = jQuery(".productList").hasClass("productSmall");
	   if(d){
		    jQuery(".productItem").each(function(){
            jQuery(this).addClass('rod');
           // var q = jQuery(this).find(".preview-img").text();
            //q = "<img src = '"+q+"'>";
            //jQuery(this).find(".preview-img").html(q);
            //jQuery(this).find(".preview-img").removeClass("hide");
           });
	   }
          newtooltip('.rod','rodTooltip','rodTooltipContent');
         	
	/* ADDED BY ROD END */
		});
	

	
/* ====================== Added by JIN ====================== */
/* --------- Code for Mobile Gallery Page --------- */
RowNum = function(lpr) {
	var cl, rl, cr, crn=1, buff=false;
	var el = jQuery("#hv_gallery .mobile_gal").length;
		rl = el; cr = lpr;

	jQuery("#hv_gallery .mobile_gal").each(function(i){
		cl = i + 1;
		rl--;

		
		if( cl == cr )
		{
			jQuery(this).addClass("nM-R");
			crn++;
			cr = lpr * crn;
		}


		
	});
}

/* ======= pricing level & product details ======= */
function level_price(){
     var copy = jQuery(".product_attrib span:first").text().substr(15,10);
     var copy2 = jQuery(".temp_price  span:first").text().substr(15,10);
     var copy3 = jQuery(".temp_price span:last").text().substr(13,10);
     jQuery(".attrib").html(copy); //for list of product pricing level
     jQuery(".after_price").html(copy2); //for product details
     jQuery(".buyout-price").html(copy3); //for buyoutprice details 
}
 function choose(){
   jQuery("#temp_custom_price input").change(function(){
			switch(  jQuery(this).val() ) {
				case 'template':
					 jQuery(".starter_price input:eq(0)").attr('checked', true);
					 jQuery("#bprice").attr('checked', false);
					 
				break;
				case 'buyout':
					 jQuery(".starter_price input:eq(1)").attr('checked', true);
                     jQuery("#tprice").attr('checked', false);
				break;
			}
			
  });
}
jQuery(function(){
  level_price();
  choose();
  
});


