if (typeof sz_hasrun == 'undefined') { sz_hasrun = 1; document.addEventListener('DOMContentLoaded',function(){ if (typeof jQuery == 'undefined') { var script = document.createElement('script'); script.type = "text/javascript"; if (script.readyState) { //IE script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; sz_callback(); } }; } else { //Others script.onload = function () { sz_callback(); }; } script.src = "//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"; document.body.appendChild(script); } else sz_callback(); }); } function sz_callback() { jQuery.wordStats = { unsortedWords: null, sortedWords: null, topWords: null, topWeights: null, _computed: false, //add words from provided string to unsortedWords array addWords: function(str, weight) { if(str && str.length > 1) { var w = this.splitWords(str.toLowerCase()); for(var x = 0, y = w.length; x < y; x++) { word = w[x]; if(word.length > 2 && !this.stopWords[word]) { word = '_' + word; if(this.unsortedWords[word]) this.unsortedWords[word] += weight; else this.unsortedWords[word] = weight; } } } }, //add words from text nodes only addWordsFromTextNodes: function(node, weight) { var nodes = node.childNodes; for(var i = 0, j = nodes.length; i < j; i++) { if(nodes[i].nodeType == 3) this.addWords(nodes[i].nodeValue, weight); } }, //accept Latin-1 basic + Latin-1 extended characters testChar: function(c) { return((c >= 97 && c <= 122) || (c >= 128 && c <= 151) || (c >= 160 && c <= 164) || (c >= 48 && c <= 57) || (c >= 224 && c <= 246) || (c >= 249 && c <= 255)); }, //split words splitWords: function(words) { var w = new Array(), str = ''; for(var i = 0, j = words.length; i < j; i++) { c = words.charCodeAt(i); if(this.testChar(c)) str += words.substring(i, i + 1); else { w.push(str); str = ''; } } if(str.length > 0) w.push(str); return(w); }, //main function: compute words from web page / element computeWords: function(elem) { if(!elem) elem = window.document; this.unsortedWords = new Array(); this.addWords(jQuery('title', elem).text(), 20); wordstats = this; jQuery('h1', elem).each(function() { wordstats.addWordsFromTextNodes(jQuery(this).get(0), 15); }); jQuery('h2', elem).each(function() { wordstats.addWordsFromTextNodes(jQuery(this).get(0), 10); }); jQuery('h3, h4, h5, h6', elem).each(function() { wordstats.addWordsFromTextNodes(jQuery(this).get(0), 5); }); jQuery('strong, b, em, i', elem).each(function() { wordstats.addWordsFromTextNodes(jQuery(this).get(0), 3); }); jQuery('p, div, th, td, li, a, span', elem).each(function() { wordstats.addWordsFromTextNodes(jQuery(this).get(0), 2); }); jQuery('img', elem).each(function() { wordstats.addWords(jQuery(this).attr('alt'), 1); wordstats.addWords(jQuery(this).attr('title'), 1); }); this._computed = true; }, //compute 'top' words: words which occur the most frequently computeTopWords: function(count, elem) { if(!this._computed) this.computeWords(elem); this.topWords = new Array(); this.topWeights = new Array(); this.topWeights.push(0); for(word in this.unsortedWords) { for(var i = 0; i < count; i++) { if(this.unsortedWords[word] > this.topWeights[i]) { this.topWeights.splice(i, 0, this.unsortedWords[word]); this.topWords.splice(i, 0, word); break; } } } }, //sort the unsortedWords array, based on words 'weights' descending sortWords: function() { this.sortedWords = new Array(); //sort the associative array desc i = 0; for(word in this.unsortedWords) { this.sortedWords[i] = word; i++; } this.sortedWords.sort(function(a, b) { return wordstats.unsortedWords[b] - wordstats.unsortedWords[a]; } ); }, //release memory clear: function() { this.unsortedWords = this.sortedWords = this.topWords = this.topWeights = null; this._computed = false; } }; jQuery.wordStats.stopWords = { 'the': true, 'that': true, 'you': true, 'your': true, 'for': true, 'are': true, 'use': true, 'our': true, 'photo': true, 'picture': true, 'photos': true, 'pictures': true, 'stock': true, 'image': true, 'images': true, 'quality': true, 'video': true, 'vector': true, 'videos': true, 'vectors': true, 'footage': true, 'jpeg': true, 'royalty': true, 'symzio': true, 'symbiostock': true, 'and': true }; jQuery(document).ready(function( $ ) { var sz_title=""; //if (typeof document.getElementsByTagName("title")[0] != 'undefined') sz_title = document.getElementsByTagName("title")[0].innerHTML; $.wordStats.computeTopWords(2); var words = $.wordStats.topWords.join(" "); words = words.replace("_", ""); $.wordStats.clear(); $(".sz_widget").each(function(){ $(this).load('//www.symzio.com/q?context=' + $(this).data('context') + '&h=' + $(this).data('h') + '&w=' + $(this).data('w') + '&maxnum=' + $(this).data('maxnum') + '&ack=' + $(this).data('ack') + '&id=' + $(this).data('cclass') + '&q=' + encodeURIComponent(words), function () { $(".sz_res_img").each(function(){ var bgbox = $( this ).next( ".symzio_searchresults_item" ); var img = new Image(); $(img).hide(); img.src = $(this).attr("src"); $(img).load(function() { bgbox.fadeIn(); }); }); }); }); }); }